当前位置: 代码迷 >> SQL >> SQL:统计工作情况例证
  详细解决方案

SQL:统计工作情况例证

热度:63   发布时间:2016-05-05 15:14:10.0
SQL:统计工作情况例子

表结构
NAME?? FINISH?? OK
A君?????????? Y????? Y
B君?????????? N
A君
A君?????????? Y????? N

显示效果
名字?? 工作量? 未完成量? 不能完成量?? 完成量?? 不通过审核?? 通过审核
A君??????? 3?????????? 1????????????????? 0???????????? 2???????????????? 1?????????????? 1
B君??????? 1????????? ?0???????????????? ?1??????????? ?0???????????????? 0?????????????? 0

~~~~~~~~~~~~~~~~~~~

SQL:

SELECT
??? name 名字,
??? count(1) 工作量,
??? sum
??? (
??????? CASE
??????????? WHEN FINISH is null
??????????? THEN 1
??????????? ELSE 0
??????? END
??? )
??? 未完成量,
??? sum
??? (
??????? CASE
??????????? WHEN FINISH = 'N'
??????????? THEN 1
??????????? ELSE 0
??????? END
??? )
??? 不能完成量,
??? sum
??? (
??????? CASE
??????????? WHEN FINISH = 'Y'
??????????? THEN 1
??????????? ELSE 0
??????? END
??? )
??? 完成量,
??? sum
??? (
??????? CASE
??????????? WHEN ok = 'N'
??????????? THEN 1
??????????? ELSE 0
??????? END
??? )
??? 不通过审核,
??? sum
??? (
??????? CASE
??????????? WHEN ok = 'Y'
??????????? THEN 1
??????????? ELSE 0
??????? END
??? )
??? 通过审核
FROM
??? test
GROUP BY
??? name

  相关解决方案