Witam,
Potrzebuję zgrupować pole I8_3 ale z warunkiem np.:
I8_3 > 1 and I8_3 < 5
select count(I8_1) from CTE_For as d group by grouping sets ( (case when I8_3 > 1 and I8_3 < 5 then 1 end), (case when I8_3 = 1 then 1 end) )
Czy jest taka możliwość w TSQL?
0
0
Kajet napisał(a):
Witam,
Potrzebuję zgrupować pole I8_3 ale z warunkiem np.:
I8_3 > 1 and I8_3 < 5
select count(I8_1) from CTE_For as d group by grouping sets ( (case when I8_3 > 1 and I8_3 < 5 then 1 end), (case when I8_3 = 1 then 1 end) )
Czy jest taka możliwość w TSQL?
Tak, jest po prostu... Coś w ten deseń:
select
(case when I8_3 > 1 and I8_3 < 5 then 1 end) as group1,
(case when I8_3 = 1 then 1 end) as group2,
count(I8_1)
from CTE_For as d
group by (case when I8_3 > 1 and I8_3 < 5 then 1 end), (case when I8_3 = 1 then 1 end)
Brakuje mi tylko w tych case
co się stanie jak warunek nie jest spełniony, czyli else
; a w ogóle to zamieniłbym case
na iif