TSQL grupowanie z warunkiem

0

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
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

1 użytkowników online, w tym zalogowanych: 0, gości: 1