zoukankan      html  css  js  c++  java
  • MySQL 统计上一周从周一到周日的用户

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

     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;
    

    原文:https://blog.csdn.net/shenxiandashu/article/details/80898807

  • 相关阅读:
    Linux中的中断处理
    Yocto使用小技巧
    udev学习笔记汇总
    USB gadget学习笔记
    Linux常用命令
    Linux下软件安装方法
    278. First Bad Version
    MySQL的索引
    7. Reverse Integer
    排序算法
  • 原文地址:https://www.cnblogs.com/showcase/p/11420041.html
Copyright © 2011-2022 走看看