简体   繁体   中英

sql query group by day of month

I have a record table that icludes dates of rows created. (oracle db)

ID    City       CreateDate
1     city-1     12.12.2017
1     city-2     13.12.2017
1     city-1     13.12.2017
1     city-3     12.12.2017
....
....

I want to create a daiy report in a month. For example City-1 report by days in December

Day    Count
1      10
2      80
3      60
4      10
...
30     11

I think you can use extract with count functions:

SELECT EXTRACT(day FROM CreateDate) "Day",
      COUNT(CreateDate) "Number of Reports"
      FROM yourTableName
      GROUP BY EXTRACT(day FROM CreateDate)
      ORDER BY "Number of Reports" ASC;

如果我正确理解,以下查询将生成您想要的12月份的报告。

SELECT EXTRACT(day FROM CreateDate) "Day", COUNT(*) "Count" FROM your_record_table WHERE EXTRACT(month FROM CreateDate) = 12 GROUP BY EXTRACT(day FROM CreateDate) ORDER BY EXTRACT(day FROM CreateDate);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM