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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Counting two separate years and status into one

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 pending

Here is what I have so far
Select 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, order
where table1.orderid = table2.orderid
and oyear in ('2009','2010','2011','2012')
and orderstatus in (2,5)
or oyear in ('2012')
and orderstatus in (1,3)
group by orderstatus
order 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 MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -