请教一个的问题
2021-09-06 来源:临清租房网
作者:王国安 请教一个case when的问题?
sql:
select count(ID) CNT,TYPEGROUP from(
select ID,
case when (COL_A0 and COL_A = 10) then 1 when (COL_A10 and COL_A =20) then 2
when (COL_A20 and COL_A =30) then 3 when (COL_A30 and COL_A =40) then 4
when (COL_A40 and COL_A =50) then 5 when (COL_A50 and COL_A =60) then 6
when (COL_A60 and COL_A =70) then 7 when (COL_A70 and COL_A =80) then 8
when (COL_A80 and COL_A =90) then 9 when (COL_A90 and COL_A =100) then 10
when (COL_A100 and COL_A =110) then 11 when (COL_A110 and COL_A =120) then 12
when (COL_A120 and COL_A =130) then 13 when (COL_A130) then 14 end TYPEGROUP
from T_TEST
) group by TYPEGROUP
order by TYPEGROUP
结果是这样的:
CNT TYPEGROUP
11 1
32 2
15 3
34 4
32 6
24 7
53 8
42 9
我希望能把其中的5,10,11,12,13,14都显示出来,只不过CNT为空或0
按这个思路应当可以的,只是没数据测试,楼主不妨试试:
select count(ID)-1 CNT,TYPEGROUP from(
select ID,
case when (COL_A0 and COL_A = 10) then 1 when (COL_A10 and COL_A =20) then 2
when (COL_A20 and COL_A =30) then 3 when (COL_A30 and COL_A =40) then 4
when (COL_A40 and COL_A =50) then 5 when (COL_A50 and COL_A =60) then 6
when (COL_A60 and COL_A =70) then 7 when (COL_A70 and COL_A =80) then 8
when (COL_A80 and COL_A =90) then 9 when (COL_A90 and COL_A =100) then 10
when (COL_A100 and COL_A =110) then 11 when (COL_A110 and COL_A =120) then 12
when (COL_A120 and COL_A =130) then 13 when (COL_A130) then 14 end TYPEGROUP
from T_TEST
union all (select 1, level from dual connect by level 15)
) group by TYPEGROUP
order by TYPEGROUP
枣庄看白癜风医院成都男科较好医院
健脾胃的中药有哪些
-
- 上一篇
- 请教的语句的