qq_31071631 于 2016.01.14 15:24 提问

SELECT COUNT(*) renshu, CASE WHEN AGE <= 10 THEN '1' WHEN AGE > 10 AND AGE <= 20 THEN '2' WHEN AGE > 20 AND AGE <= 30 THEN '3' WHEN AGE > 30 AND AGE <= 40 THEN '4' WHEN AGE > 40 AND AGE <= 50 THEN '5' WHEN AGE > 50 AND AGE <= 60 THEN '6' WHEN AGE > 60 AND AGE <= 70 THEN '7' WHEN AGE > 70 AND AGE <= 80 THEN '8' WHEN AGE > 80 AND AGE <= 90 THEN '9' WHEN AGE > 90 AND AGE <= 100 THEN 'a' WHEN AGE > 100 THEN 'b' END allshuju ,OUT_MAIN_DIAG_RST leibie FROM WORK_BASY_DATA where OUT_DT >= '2014-10-01' and OUT_DT <='2014-10-31' GROUP BY allshuju这段时间里没有100以上，怎么样让100也出来显示0

5个回答

CSDNXIAON   2016.01.14 15:25

----------------------同志你好，我是CSDN问答机器人小N，奉组织之命为你提供参考答案，编程尚未成功，同志仍需努力！

zy_281870667      2016.01.14 15:34

SELECT COUNT(*) renshu, CASE WHEN AGE <= 10 THEN '1' WHEN AGE > 10 AND AGE <= 20 THEN '2' WHEN AGE > 20 AND AGE <= 30 THEN '3' WHEN AGE > 30 AND AGE <= 40 THEN '4' WHEN AGE > 40 AND AGE <= 50 THEN '5' WHEN AGE > 50 AND AGE <= 60 THEN '6' WHEN AGE > 60 AND AGE <= 70 THEN '7' WHEN AGE > 70 AND AGE <= 80 THEN '8' WHEN AGE > 80 AND AGE <= 90 THEN '9' WHEN AGE > 90 AND AGE <= 100 THEN 'a' WHEN AGE > 100 THEN '0' END allshuju ,OUT_MAIN_DIAG_RST leibie FROM WORK_BASY_DATA where OUT_DT >= '2014-10-01' and OUT_DT <='2014-10-31' GROUP BY allshuju

m86872125   2016.01.14 15:36

qq_31071631 就是没有数据，显示为0
2 年多之前 回复
save4me      2016.01.15 12:15

``````SELECT COUNT (*) renshu
, CASE
WHEN MONTH(DocDate) = 1 THEN '1'
WHEN MONTH(DocDate) = 2 THEN '2'
WHEN AGE <= 10 THEN '1'
WHEN AGE > 10 AND AGE <= 20 THEN '2'
WHEN AGE > 20 AND AGE <= 30 THEN '3'
WHEN AGE > 30 AND AGE <= 40 THEN '4'
WHEN AGE > 40 AND AGE <= 50 THEN '5'
WHEN AGE > 50 AND AGE <= 60 THEN '6'
WHEN AGE > 60 AND AGE <= 70 THEN '7'
WHEN AGE > 70 AND AGE <= 80 THEN '8'
WHEN AGE > 80 AND AGE <= 90 THEN '9'
WHEN AGE > 90 AND AGE <= 100 THEN 'a'
WHEN AGE > 100 THEN 'b'
END allshuju
, OUT_MAIN_DIAG_RST leibie
FROM WORK_BASY_DATA
WHERE OUT_DT >= '2014-10-01' AND OUT_DT <= '2014-10-31'
GROUP BY (CASE
WHEN MONTH(DocDate) = 1 THEN '1'
WHEN MONTH(DocDate) = 2 THEN '2'
WHEN AGE <= 10 THEN '1'
WHEN AGE > 10 AND AGE <= 20 THEN '2'
WHEN AGE > 20 AND AGE <= 30 THEN '3'
WHEN AGE > 30 AND AGE <= 40 THEN '4'
WHEN AGE > 40 AND AGE <= 50 THEN '5'
WHEN AGE > 50 AND AGE <= 60 THEN '6'
WHEN AGE > 60 AND AGE <= 70 THEN '7'
WHEN AGE > 70 AND AGE <= 80 THEN '8'
WHEN AGE > 80 AND AGE <= 90 THEN '9'
WHEN AGE > 90 AND AGE <= 100 THEN 'a'
WHEN AGE > 100 THEN 'b'
END),
OUT_MAIN_DIAG_RST
``````
save4me      2016.01.15 12:16

``````SELECT COUNT (*) renshu
, CASE
WHEN AGE <= 10 THEN '1'
WHEN AGE > 10 AND AGE <= 20 THEN '2'
WHEN AGE > 20 AND AGE <= 30 THEN '3'
WHEN AGE > 30 AND AGE <= 40 THEN '4'
WHEN AGE > 40 AND AGE <= 50 THEN '5'
WHEN AGE > 50 AND AGE <= 60 THEN '6'
WHEN AGE > 60 AND AGE <= 70 THEN '7'
WHEN AGE > 70 AND AGE <= 80 THEN '8'
WHEN AGE > 80 AND AGE <= 90 THEN '9'
WHEN AGE > 90 AND AGE <= 100 THEN 'a'
WHEN AGE > 100 THEN 'b'
END allshuju
, OUT_MAIN_DIAG_RST leibie
FROM WORK_BASY_DATA
WHERE OUT_DT >= '2014-10-01' AND OUT_DT <= '2014-10-31'
GROUP BY (CASE
WHEN MONTH(DocDate) = 1 THEN '1'
WHEN MONTH(DocDate) = 2 THEN '2'
WHEN AGE <= 10 THEN '1'
WHEN AGE > 10 AND AGE <= 20 THEN '2'
WHEN AGE > 20 AND AGE <= 30 THEN '3'
WHEN AGE > 30 AND AGE <= 40 THEN '4'
WHEN AGE > 40 AND AGE <= 50 THEN '5'
WHEN AGE > 50 AND AGE <= 60 THEN '6'
WHEN AGE > 60 AND AGE <= 70 THEN '7'
WHEN AGE > 70 AND AGE <= 80 THEN '8'
WHEN AGE > 80 AND AGE <= 90 THEN '9'
WHEN AGE > 90 AND AGE <= 100 THEN 'a'
WHEN AGE > 100 THEN 'b'
END),
OUT_MAIN_DIAG_RST
``````