SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2012 Forums
 Other SQL Server 2012 Topics
 Help
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

IEyeScream
Starting Member

Philippines
6 Posts

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

need help for the query please

bandi
Flowing Fount of Yak Knowledge

India
2170 Posts

Posted - 05/22/2013 :  03:31:13  Show Profile  Reply with Quote
--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

India
52249 Posts

Posted - 05/22/2013 :  03:44:14  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

India
2170 Posts

Posted - 05/22/2013 :  06:41:33  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000