码迷,mamicode.com
首页 > 数据库 > 详细

sql 聚合语句,count的用法

时间:2018-07-10 16:49:11      阅读:277      评论:0      收藏:0      [点我收藏+]

标签:format   str   when   span   batch   eid   res   The   col   

如要获取 result = ‘1‘ 的数量
COUNT(   CASE   WHEN result = ‘1‘ THEN   result   END )

 

SELECT
  *
FROM
(
SELECT
batchNo,
serviceId,
result,
projectId,
sum(passCount) AS passCount,
COUNT(
CASE
WHEN result = 1 THEN
result
END
) AS quality,
COUNT(
CASE
WHEN (result = 2 OR result = 0) THEN
result
END
) AS type,
COUNT(
CASE
WHEN result = 2 THEN
result
END
) AS qualityTime,
COUNT(
CASE
WHEN result = 0 THEN
result
END
) AS qualityName,
COUNT(questionId) AS questionId,
sum(auditCount) AS auditCount,
auditTime,
id,
serviceName
FROM
picture_audit_helper
WHERE
1 = 1
GROUP BY
serviceName,
DATE_FORMAT(auditTime, %Y-%m-%d)
) AS t
GROUP BY
auditTime DESC
LIMIT 1

 

sql 聚合语句,count的用法

标签:format   str   when   span   batch   eid   res   The   col   

原文地址:https://www.cnblogs.com/lemon-flm/p/9289753.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!