当前位置:Gxlcms > mysql > 那在sqlserver中该怎么写才能达到mysql中的分组效果呢,分出的结果不一样

那在sqlserver中该怎么写才能达到mysql中的分组效果呢,分出的结果不一样

时间:2021-07-01 10:21:17 帮助过:30人阅读

mysqlsql server

SELECT 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 ,COUNT(*) renshu,OUT_MAIN_DIAG_RST leibie FROM WORK_BASY_DATA where 1=1 and OUT_DT >= '2012-10-1' and OUT_DT <= '2012-10-31' GROUP BY allshuju,OUT_MAIN_DIAG_RST having OUT_MAIN_DIAG_RST!='' AND allshuju!=''

人气教程排行