关闭

mysql 横表查询转竖表case when()

850人阅读 评论(0) 收藏 举报


SELECT app_id,

SUM(CASE  WHEN prev_user_id=0 AND _status=0 THEN 1 ELSE 0 END) AS commit_deny,
SUM(CASE  WHEN prev_user_id>0 AND _status=0 THEN 1 ELSE 0 END) AS get_deny,
SUM(CASE  WHEN prev_user_id=0 AND _status>0 THEN 1 ELSE 0 END) AS commit_approval,
SUM(CASE  WHEN prev_user_id>0 AND _status>0 THEN 1 ELSE 0 END) AS get_approval,
SUM(CASE  WHEN prev_user_id=0 AND _status=-1 THEN 1 ELSE 0 END) AS commit_commit,
SUM(CASE  WHEN prev_user_id>0 AND _status=-1 THEN 1 ELSE 0 END) AS get_commit


FROM xxxxx WHERE (upload_method=0 OR upload_method=2)  GROUP BY app_id;


AND  (ctime>=:1 AND ctime<=:2)
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:37811次
    • 积分:959
    • 等级:
    • 排名:千里之外
    • 原创:54篇
    • 转载:12篇
    • 译文:1篇
    • 评论:2条
    文章分类