我有一个称为 activity_dt 的日期时间,数据如下所示:
2/5/2013 9:24:00 AM 2/7/2013 7:17:00 AM
如何按日期和小时分组?
SQL Server:
SELECT [activity_dt], count(*) FROM table1 GROUP BY DATEPART(day, [activity_dt]), DATEPART(hour, [activity_dt]);
甲骨文:
SELECT [activity_dt], count(*) FROM table1 GROUP BY TO_CHAR(activity_dt, 'DD'), TO_CHAR(activity_dt, 'hh');
MySQL的:
SELECT [activity_dt], count(*) FROM table1 GROUP BY hour( activity_dt ) , day( activity_dt )