sql 聚合语句,count的用法

Posted 低调人生

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql 聚合语句,count的用法相关的知识,希望对你有一定的参考价值。

如要获取 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的用法的主要内容,如果未能解决你的问题,请参考以下文章

SQL数据库中聚合函数SUM和COUNT的用法

sql 2005 聚合函数

sql聚合函数的应用

数据库查询,关于聚合函数 max()的用法。

sql 聚合函数都有哪些

sql server中啥是聚合函数