I guess it is hard to understand. but i have written a sample of code.
this sample is good if the customer choose population_1 that means
ind_1 > 0
ind_2 > 0
or population_2 that means
ind_2 > 0
ind_3 > 0
or any unique population, my problem is that i want to provide a drop down where the customer will choose population_1 , population_2, population_3, population_4, etc, or any combination of the list.
i thought about using if, but talking in consideration that i have 10 different population, the number of combinations is a bit more code that i think it should be written for every possibility.
with population_1
as
(
select userid from mysample where ind_1 > 0
union
select userid from mysample where ind_2 > 0
), sumas
as
(
select populations, count(userid) as NumberofUsersBad, sum(amountspent) as TotalSpendBad
from mysample
where userid in (select userid from population_1)
group by populations
), panel
as
(
select populations, count(userid) as NumberofUsersTotal, sum(amountspent) as TotalSpend
from mysample
group by populations
)
select p.populations, sum(p.NumberofUsersTotal) as NumberofUsersTotal,
sum(s.NumberofUsersBad) as NumberofUsersBad,
sum(p.TotalSpend) as TotalSpend,
sum(s.TotalSpendBad) as TotalSpendBad
from panel p join sumas s on p.populations = s.populations
group by p.populations