Home > database >  How to according to the last day of every month in oracle the total number of statistics in deadline
How to according to the last day of every month in oracle the total number of statistics in deadline

Time:05-11

SQL small white want to query the total number of orders by the end of every month, but I will only simple query as the total number of a certain date:

SELECT count (order) FROM t_hy
WHERE to_char (rq, '- DD YYYY - MM) & lt;
='2021-04-30'
Use this method to check from January 20 years up to now, by the total number of orders per month (such as the total number of as of March 31, 21 years, as of February 28, the total number of), can only check one by one, the efficiency is too low, could you tell me your bosses, what method can one-time found out? Thank you

CodePudding user response:

GROUP BY!

CodePudding user response:

The select to_char (rq, 'yyyy) as Y,
To_char (rq, 'mm) as M,
Count (order)
The from t_hy
Where to_char (rq, '- DD YYYY - MM) & lt;
='2021-04-30'Group by to_char (rq, 'yyyy), to_char (rq,' mm)
The order by to_char (rq, 'yyyy), to_char (rq,' mm.)
  • Related