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 2012 Forums
 Other SQL Server 2012 Topics
 Help

Author  Topic 

IEyeScream
Starting Member

6 Posts

Posted - 2013-05-22 : 02:53:34
List of customers including their ordered product and its price per product. Also include subtotal.Click URL to See the Tables [url]https://fbcdn-sphotos-b-a.akamaihd.net/hphotos-ak-frc3/261607_4470109405442_2069214335_n.jpg[/url]

need help for the query please

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-05-22 : 03:31:13
--this?

SELECT c.CustomerCode, c.FirstName, sp.ProdCode, SUM(sp.CurrentPrice) PricePerProduct
FROM Customer c
JOIN Order o ON o.CustomerCode = c.CustomerCode
JOIN OrderDetails od ON od.OrderCode = o.OrderCode
JOIN SetPrice sp ON sp.SetPriceCode = od.SetPriceCode
GROUP BY c.CustomerCode, c.FirstName, sp.ProdCode

--
Chandu
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-05-22 : 03:44:14
Make sure you use LEFT JOIN instead of JOIN in above case if you've Customers who have not ordered yet and still want to retrieve them in your result.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-05-22 : 06:41:33
Hi,
Don't open duplicate threads for same query....
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=185501#724970

--
Chandu
Go to Top of Page
   

- Advertisement -