sql server - SQL Get results back from every items in IN() -
hi can 1 me this?
i have made query:
select distinct(campaign), count(status) c18_101 inner join client_10 on c18_101.id = client_10.id campaign in ('batch 1','batch 2','batch 3','batch 4','batch 5') , status = 'pending' group campaign,status
the result looks this:
batch 2 241 batch 3 321 batch 4 575 batch 5 429
i need result batch1 when there none.
select x.campaign, count(status) (select distinct campaign c18_101) x left join client_10 c on x.id = c.id , c.status = 'pending' group x.campaign
- you either group or aggregate, not both
- you distinct before join ensure counts correct per campaign
- do need campaign filter? if so, add derived table x
Comments
Post a Comment