SQL数据库中日期时间类型,按日期group by 实现

时间:2023-03-09 17:21:16
SQL数据库中日期时间类型,按日期group by 实现

每天学习一点点 编程PDF电子书免费下载: http://www.shitanlife.com/code

cast(starttime as date):  时间转日期类型

实例SQL:

SELECT
COUNT (ID) AS pvNum,
COUNT (DISTINCT userid) AS userNum,
cast(starttime as date) AS staDay
FROM
t_e_visit_record
WHERE true
AND starttime >= '2018-03-20'
GROUP BY
cast(starttime as date)