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 |
magmo
Aged Yak Warrior
558 Posts |
Posted - 2006-08-21 : 04:15:08
|
HiThis is a part of q query I have the need to display the total sum of the "Qty" and dbo.tbl_Order.ProductPriceSELECT DISTINCT dbo.tbl_Order.NodeID, SUM(dbo.tbl_Order.Quantity) AS QtyHow do I get this to work? |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-08-21 : 04:23:29
|
Don't quite understand what you want here. Maybe you can post the table DDL, some sample data and the result that you want. KH |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-08-21 : 04:33:47
|
Try thisSELECT dbo.tbl_Order.NodeID, SUM(dbo.tbl_Order.Quantity) AS Qty, MAX(dbo.tbl_Order.ProductPrice) GROUP BY dbo.tbl_Order.NodeID Peter LarssonHelsingborg, Sweden |
|
|
magmo
Aged Yak Warrior
558 Posts |
Posted - 2006-08-21 : 04:44:12
|
HiThere are 4 different tables and the complete query looks like this...SELECT DISTINCT dbo.tbl_Order.NodeID, SUM(dbo.tbl_Order.Quantity) AS Qty, dbo.tbl_Products.Text, dbo.tbl_Login.CustIDFROM dbo.tbl_Order INNER JOIN dbo.tbl_Products ON dbo.tbl_Order.NodeID = dbo.tbl_Products.NodeId INNER JOIN dbo.tbl_Login ON dbo.tbl_Order.UserUniqueID = dbo.tbl_Login.UID INNER JOIN dbo.tbl_OrderInfo ON dbo.tbl_Order.CartID = dbo.tbl_OrderInfo.CartIDWHERE (dbo.tbl_Order.DateOrdered BETWEEN CONVERT(DATETIME, '2006-04-01', 102) AND CONVERT(DATETIME, '2006-05-01', 102))GROUP BY dbo.tbl_Order.NodeID, dbo.tbl_Products.Text, dbo.tbl_Login.CustIDHAVING (dbo.tbl_Login.CustID = 20)That query give me a result like this...NodeID Qty Text CustID1 200 prod 1 52 150 prod 2 53 400 prod 3 5But I would also like to display the total sum like this...NodeID Qty Text CustID Price TotalSum1 200 prod 1 5 10 20002 150 prod 2 5 5 7503 400 prod 3 5 87 34800Hope this helpRegards |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-08-21 : 04:51:55
|
[code]SELECT dbo.tbl_Order.NodeID, SUM(dbo.tbl_Order.Quantity) AS Qty, dbo.tbl_Products.Text, dbo.tbl_Login.CustID, MAX(dbo.tbl_Products.Price) Price, SUM(dbo.tbl_Order.Quantity) * MAX(dbo.tbl_Products.Price) TotalSumFROM dbo.tbl_OrderINNER JOIN dbo.tbl_Products ON dbo.tbl_Order.NodeID = dbo.tbl_Products.NodeIdINNER JOIN dbo.tbl_Login ON dbo.tbl_Order.UserUniqueID = dbo.tbl_Login.UID AND dbo.tbl_Login.CustID = 20INNER JOIN dbo.tbl_OrderInfo ON dbo.tbl_Order.CartID = dbo.tbl_OrderInfo.CartIDWHERE dbo.tbl_Order.DateOrdered BETWEEN CONVERT(DATETIME, '2006-04-01', 102) AND CONVERT(DATETIME, '2006-05-01', 102)GROUP BY dbo.tbl_Order.NodeID, dbo.tbl_Products.Text, dbo.tbl_Login.CustID[/code]Peter LarssonHelsingborg, Sweden |
|
|
magmo
Aged Yak Warrior
558 Posts |
Posted - 2006-08-21 : 05:01:11
|
Excellent Peter, Thanks :-) |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-08-21 : 07:27:33
|
Thanks for the feed-back!Peter LarssonHelsingborg, Sweden |
|
|
|
|
|
|
|