DateTime按日期和小时分组
我有一个称为 的日期时间,数据如下所示:
2/5/2013 9:24:00 AM2/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 )
以上是 DateTime按日期和小时分组 的全部内容, 来源链接: utcz.com/qa/430609.html