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
 General SQL Server Forums
 New to SQL Server Programming
 SUM and JOIN Query ???
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

chulz90
Starting Member

Indonesia
26 Posts

Posted - 11/29/2012 :  02:08:58  Show Profile  Reply with Quote
hello guys, i've some case. please help me to fix this case

tb_item
item Name brand
B1 item 1 M1
B2 item 2 M2
B3 item 3 M3
B4 item 4 M4

tb_brand
brand brand name
M1 brand 1
M2 brand 2
M3 brand 3
M4 brand 4

tb_quantity
item quantity
B1 10
B2 30
B3 20
B4 25
B1 30
B1 60
B2 50
B3 20

the question is, how to summarize in tb_quantity with the view below, using SUM and JOIN

this is the SQL View
item Name total brand name
B1 item 1 100 brand 1
B2 item 2 80 brand 2
B3 item 3 40 brand 3
B4 item 4 25 brand 4

please help me

bandi
Flowing Fount of Yak Knowledge

India
2202 Posts

Posted - 11/29/2012 :  02:29:23  Show Profile  Reply with Quote

SELECT i.item, name, total, brandname
FROM @tb_item i 
JOIN @tb_brand b ON i.brand = b.brand
JOIN (SELECT item, SUM(quantity) total FROM @tb_quantity GROUP BY item) q ON q.item = i.item


--
Chandu
Go to Top of Page

chulz90
Starting Member

Indonesia
26 Posts

Posted - 11/29/2012 :  02:39:58  Show Profile  Reply with Quote
quote:
Originally posted by bandi


SELECT i.item, name, total, brandname
FROM @tb_item i 
JOIN @tb_brand b ON i.brand = b.brand
JOIN (SELECT item, SUM(quantity) total FROM @tb_quantity GROUP BY item) q ON q.item = i.item


--
Chandu



thank's so much chandu
Go to Top of Page

bandi
Flowing Fount of Yak Knowledge

India
2202 Posts

Posted - 11/29/2012 :  04:11:29  Show Profile  Reply with Quote
quote:
Originally posted by chulz90


thank's so much chandu



Welcome

--
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.03 seconds. Powered By: Snitz Forums 2000