美文网首页
mysql经典面试题 count()加条件判断

mysql经典面试题 count()加条件判断

作者: xudong7930 | 来源:发表于2020-03-20 10:09 被阅读0次

    面试题:某部门员工的打开记录user_signs 如下, 用一条SQL统计出员工的出勤次数,迟到次数和迟到总时长:

    ID date name delay_time
    1 2020-01-01 张三 0
    2 2020-01-01 李四 10
    3 2020-01-01 王五 2
    4 2020-01-02 张三 5
    5 2020-01-02 李四 0
    6 2020-01-02 王五 4

    答案:

    select name,sum(delay_time), count(1), count(if(delay_time>0, true, null)) from user_signs group by name
    

    相关文章

      网友评论

          本文标题:mysql经典面试题 count()加条件判断

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