Yii2

Mysql 查询一天中,每个小时数据的数量

2018-01-06  本文已影响206人  方圆百里找对手

其中 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');
上一篇 下一篇

猜你喜欢

热点阅读