其中 created_at
是时间戳,如果是时间格式那么无需 FROM_UNIXTIME
转换。
SELECT
HOUR (FROM_UNIXTIME(created_at)) AS Hour,
count(*) AS Count
FROM
yun_user
WHERE
FROM_UNIXTIME(created_at, '%Y-%m-%d') = '2018-01-03'
GROUP BY
HOUR (FROM_UNIXTIME(created_at))
ORDER BY
HOUR (FROM_UNIXTIME(created_at));
SELECT
FROM_UNIXTIME(created_at,'%H') AS Hour,
count(*) AS Count
FROM
yun_user
WHERE
FROM_UNIXTIME(created_at, '%Y-%m-%d') = '2018-01-03'
GROUP BY
FROM_UNIXTIME(created_at,'%H')
ORDER BY
FROM_UNIXTIME(created_at,'%H');
网友评论