sql server - multiple SQL counts using multiple queries using SQL -
i need multiple counts. have 6 columns. this:
select count(c.id) 'column 1', count(c.id) 'column 2', count(c.id) 'column 3', count(c.id) 'column 4', contact c
i need able run different counts using different queries unsure how apply queries counts in 1 result.
you have several options here.
1) use subqueries @thesoultion proposed
2) use use union
select 'a' name, count(c.id) [count] contact c ... union select 'b' name, count(c.id) [count] contact c ...
3) in case same subset want sum based on conditions, use case when inside counts
select sum(case ... when ... 1 else 0 end) counta, sum(case ... when ... 1 else 0 end) countb ... ...
Comments
Post a Comment