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 2000 Forums
 Transact-SQL (2000)
 pick order amount by category

Author  Topic 

imughal
Posting Yak Master

192 Posts

Posted - 2004-06-25 : 07:20:24
hi,

i want to get amount by each category. my table structure is

1.order [orderid, total (varchar)]
2.items [orderid,productid, ]
3.products [productid, categoryid]
4. categories [categoryid,categoryname]

the result should be like

categoryid categoryname totalamount
1 abc 1000
2 xyz 5000


regards,
im

Wanderer
Master Smack Fu Yak Hacker

1168 Posts

Posted - 2004-06-25 : 07:51:28
select c.categoryid,c.categoryname,sum(cast ((o.total) as dec (10,2)) ) as totalamount
from [order] o inner join
items i on o.orderid = i.orderid
inner join products p
on i.productid = p.productid
inner join category c
on p.categoryid = c.categoryid
group by c.categoryid,c.categoryname


*##* *##* *##* *##*

Chaos, Disorder and Panic ... my work is done here!
Go to Top of Page
   

- Advertisement -