Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
need help writing query which shows results like this ... department male femalea 2 5b 3 6c 5 3d 6 2e 7 1f 8 4g 9 7can anyone help please ...
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts
Posted - 2010-03-31 : 12:00:52
sure..
select 'a' as department, 2 as male, 5 as female union allselect 'b',3,6 union allselect 'c',5,3 union allselect 'd',6,2 union allselect 'e',7,1 union allselect 'f',8,4 union allselect 'g',9,7
Easy enough?Harsh Athalyehttp://www.letsgeek.net/
madhivanan
Premature Yak Congratulator
22864 Posts
Posted - 2010-04-01 : 05:25:44
Select department ,sum(case when sex='M' then 1 else 0 end) as male,sum(case when sex='F' then 1 else 0 end) as female,from your_tablegroup by department MadhivananFailing to plan is Planning to fail
visakh16
Very Important crosS Applying yaK Herder
52326 Posts
Posted - 2010-04-01 : 05:41:34
make sure you post your table structures along with some sample data while posting questions in future. they will enable us to give accurate and quick solns------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/