weixin_39909633
weixin_39909633
2017-10-17 09:22
采纳率: 100%
浏览 1.1k

求大神!!!同时查出 多个字段的重复次数的 sql语句怎么写

图片说明
得到的结果是这样的图片说明

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

6条回答 默认 最新

  • pcwblover008
    TheTimeIsPassing 2017-10-17 13:49
    已采纳

    select uid,
    sum(case when typename='迟到' then 1 else 0 end) as '迟到',
    sum(case when typename='早退' then 1 else 0 end) as '早退',
    sum(case when typename='旷工' then 1 else 0 end) as '旷工'
    from t_mutivalue
    group by uid

    mysql亲测

    执行结果

    点赞 评论
  • qq_20803639
    上帝是笨蛋i 2017-10-17 09:43

    MySQL集合,里面好像有的,忘记是哪个了,那就查查MySQL手册

    点赞 评论
  • a314066646
    FEN_TA 2017-10-17 09:46

    select id,count(case when typename='迟到' then 1 end) as "迟到",count(case when typename='早退' then 1 end) as '早退',count(case when typename= '旷工'' then 1 end ) as '旷工' from table group by id

    点赞 评论
  • Kuroro_Lucifer
    Kuroro_Lucifer 2017-10-17 09:49

    select count(*) where typename = #{XXX};

    点赞 评论
  • yy339452689

    select * from (select count(*),typename from tablename group by typename) a

    点赞 评论
  • yisuylm
    日月路明 2017-10-17 13:09

    select UID,
    迟到=sum(case when typename='迟到' then 1 else 0 end),
    早退=sum(case when typename='早退' then 1 else 0 end),
    旷工=sum(case when typename='旷工' then 1 else 0 end)
    from table
    group by uid

    点赞 评论

相关推荐