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.
| Author |
Topic |
|
rajeshdbabu
Starting Member
2 Posts |
Posted - 2012-01-16 : 12:26:24
|
| hi experts,i am newbie, please help me with my sql querytable1id X1 12 13 11 13 1table2id Y1 12 14 15 12 1required outputid X Y1 2 12 1 23 2 04 0 15 0 1my following query produces wrong output, please help me to correct/rewrite itselect id, count(X) from table1 group by id, Xunionselect id, count(Y) from table1 group by id, Xmany thanksRaj |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-01-16 : 12:30:34
|
| [code]select coalesce(m.id,n.id) as id,coalesce(m.cnt,0) AS [X],coalesce(n.cnt,0) AS [Y]from(select id, count(X) as cnt from table1 group by id)mfull outer join(select id, count(Y) from table1 group by id)non n.id = m.id[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
rajeshdbabu
Starting Member
2 Posts |
Posted - 2012-01-17 : 10:56:37
|
| Hi Visakh, Thank you very much for your helpful reply, Raj |
 |
|
|
|
|
|
|
|