Author |
Topic |
ttran
Starting Member
23 Posts |
Posted - 2006-10-12 : 15:31:11
|
Hi,Could someone help me how put multiple count(*) on the same output line. Or is it possible?I have 4 different counts:(1) select a.psc,a.ec,a.sx,count(*) as Full1from stf a inner join sta b on a.id = b.idwhere a.del = 0 and b.del = 0 and b.jc in ('23','42','52') and b.pt > 96group by a.psc,a.ec,a.sx(2)select a.psc,a.ec,a.sx,count(*) as Part1from stf a inner join sta b on a.id = b.idwhere a.del = 0 and b.del = 0 and b.jc in ('23','42','52') and b.pt <= 96group by a.psc,a.ec,a.sx(3)select a.psc,a.ec,a.sx,count(*) as Full2from stf a inner join sta b on a.id = b.idwhere a.del = 0 and b.del = 0 and b.jc not in ('23','42','52') and b.pt > 96group by a.psc,a.ec,a.sx(4)select a.psc,a.ec,a.sx,count(*) as Part2from stf a inner join sta b on a.id = b.idwhere a.del = 0 and b.del = 0 and b.jc not in ('23','42','52') and b.pt <= 96group by a.psc,a.ec,a.sxI want the output like:psc ec sx Full1 Part1 Full2 Part2Thank you in advance.ttran |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-10-12 : 16:14:21
|
[code]select a.psc, a.ec, a.sx, sum(case when b.jc in ('23','42','52') and b.pt > 96 then 1 else 0 end) as Full1, sum(case when b.jc in ('23','42','52') and b.pt <= 96 then 1 else 0 end) as Part1, sum(case when b.jc not in ('23','42','52') and b.pt > 96 then 1 else 0 end) as Full2, sum(case when b.jc not in ('23','42','52') and b.pt <= 96 then 1 else 0 end) as Part2from stf ainner join sta b on a.id = b.id and b.del = 0where a.del = 0group by a.psc, a.ec, a.sx[/code]Peter LarssonHelsingborg, Sweden |
 |
|
ttran
Starting Member
23 Posts |
Posted - 2006-10-12 : 17:16:29
|
Awesome !!That's exactly what I want.Thank you. Thank you.ttran |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-10-12 : 21:10:32
|
For more information read about Cross-tab Reports in sql server help fileMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|