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)
 count and sum

Author  Topic 

magmo
Aged Yak Warrior

558 Posts

Posted - 2010-08-27 : 05:40:16
Hi

I have a query that look like this..


SELECT UserID, Quantity, Price, NodeID
FROM dbo.tbl_ShoppingCart
WHERE (UserID = N'903-3016-157')


This give me ...


UserID Quantity Price NodeID
903-3016-157 200 1.00 428
903-3016-157 30 14.00 431
903-3016-157 200 1.00 432
903-3016-157 100 33.00 442
903-3016-157 200 19.00 310



Can someone show me how I can sum each subtotal (Quantity * Price) and also count the number of NodeID so that I would get a result like this...


SumTotal Qty
7920 5

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2010-08-27 : 06:09:00
[code]select UserID,sum(Quantity* Price) as SumTotal,count(NodeID) from dbo.tbl_ShoppingCart
group by UserID[/code]
Go to Top of Page

magmo
Aged Yak Warrior

558 Posts

Posted - 2010-08-27 : 06:36:07
Hi

Worked perfect, Thanks a lot!
Go to Top of Page

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2010-08-27 : 06:37:12
np
Go to Top of Page
   

- Advertisement -