Java – multiple counts in a single query – Oracle
•
Java
I need to calculate two data in the same table for two time periods
SELECT COUNT(CASE WHEN click_date='2011-06-20' THEN 0 ELSE 1 END) AS ThisDayCount,COUNT(1) ToDayCount FROM MyTable WHERE click_date BETWEEN '2011-05-01'AND 2011-06-20;
So basically, I want to calculate thisdaycount from one day and calculate from May 1, 2011 to May 20, 2011
click_ Date is a string
Solution
SELECT COUNT( CASE
SELECT COUNT( CASE WHEN click_date='2011-06-20' THEN 1 ELSE NULL END ) AS ThisDayCount,COUNT(*) AS ToDayCount FROM MyTable WHERE click_date BETWEEN '2011-05-01' AND '2011-06-20' ;
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码