美文网首页Yii2
Mysql 查询一天中,每个小时数据的数量

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

作者: 方圆百里找对手 | 来源:发表于2018-01-06 19:53 被阅读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');
    

    相关文章

      网友评论

        本文标题:Mysql 查询一天中,每个小时数据的数量

        本文链接:https://www.haomeiwen.com/subject/bpfunxtx.html