SQL Server : need a query -


i have 3 tables -

table_1 accid0v    fcustn0v  1210001       1210002       b 1210003       c  table_2 accid0v    cases0v  1210001     open 1210001     open 1210001   resolved 1210002   resolved 1210003     open  table_3 accid0v     actd0v  1210001     2/16/2014 1210002     4/5/2014 1210003     6/8/2014 

i want show data this

accid0v  fcustn0v   actd0v   total  open  1210001          2/16/2014   3      2 1210002    b       4/5/2014    1      0 1210003    c       6/8/2014    1      1 

i using sql server 2008.

a straight forward join group by it;

select    a.accid0v, a.fcustn0v, c.actd0v,   count(*) total, sum(case when b.cases0v='open' 1 else 0 end) [open] table_1  join table_2 b on a.accid0v = b.accid0v join table_3 c on a.accid0v = c.accid0v group a.accid0v, a.fcustn0v, c.actd0v 

an sqlfiddle test with.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -