MySQL 统计上一周从周一到周日的用户

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/shenxiandashu/article/details/80898807

这个功能按理说很常见,奇怪的是很难搜索到一个合适的。稍微整理了下,具体的就不展开了,注意这个表中的时间为毫秒,这条语句拷贝复制就能用。照顾大部分的无脑码农。

 SELECT
            case
                when FROM_UNIXTIME(u.time_c/1000, '%w') = 0 then '0'
                when FROM_UNIXTIME(u.time_c/1000, '%w') = 1 then '1'
                when FROM_UNIXTIME(u.time_c/1000, '%w') = 2 then '2'
                when FROM_UNIXTIME(u.time_c/1000, '%w') = 3 then '3'
                when FROM_UNIXTIME(u.time_c/1000, '%w') = 4 then '4'
                when FROM_UNIXTIME(u.time_c/1000, '%w') = 5 then '5'
                when FROM_UNIXTIME(u.time_c/1000, '%w') = 6 then '6'
            end as name, count(id) as total
        FROM user_t as u WHERE (YEARWEEK(FROM_UNIXTIME(u.time_c/1000, '%Y-%m-%d')) = YEARWEEK(now())-1) and status = 1 group by
            case
                when FROM_UNIXTIME(u.time_c/1000, '%w') = 0 then '0'
                when FROM_UNIXTIME(u.time_c/1000, '%w') = 1 then '1'
                when FROM_UNIXTIME(u.time_c/1000, '%w') = 2 then '2'
                when FROM_UNIXTIME(u.time_c/1000, '%w') = 3 then '3'
                when FROM_UNIXTIME(u.time_c/1000, '%w') = 4 then '4'
                when FROM_UNIXTIME(u.time_c/1000, '%w') = 5 then '5'
                when FROM_UNIXTIME(u.time_c/1000, '%w') = 6 then '6'
            end
        order by null;
展开阅读全文

没有更多推荐了,返回首页