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 |
Sinha
Starting Member
1 Post |
Posted - 2012-03-22 : 15:28:00
|
I have to create a query where the years are 2009,2010,2011,2012 and the order status is delivered, then there is year 2012 where the order status is pending. Need help with the code. I need to count rows in both instances where order staus is delivered or it is pendingHere is what I have so farSelect county "County",count(DECODE(Owner.oYEAR,'2009', orderstatus )) "delivered 2009",count(DECODE(owner.oYEAR,'2010', orderstatus)) "delivered 2010",Count (DECODE(owner.oYEAR,'2011', orderstatus)) "delivered 2011",Count (DECODE(owner.oYEAR,'2012', orderstatus)) "Pending 2012",count(oYEAR) "Total by Year",count (orderstatus)"Total"from owner, orderwhere table1.orderid = table2.orderidand oyear in ('2009','2010','2011','2012')and orderstatus in (2,5) or oyear in ('2012')and orderstatus in (1,3)group by orderstatusorder by orderstatus |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-03-22 : 15:58:22
|
is this SQL server? it looks like Oracle------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|
|