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 |
chulz90
Starting Member
26 Posts |
Posted - 2012-11-29 : 02:08:58
|
hello guys, i've some case. please help me to fix this casetb_itemitem Name brandB1 item 1 M1B2 item 2 M2B3 item 3 M3B4 item 4 M4 tb_brandbrand brand nameM1 brand 1M2 brand 2M3 brand 3M4 brand 4 tb_quantityitem quantityB1 10B2 30B3 20B4 25B1 30B1 60B2 50B3 20the question is, how to summarize in tb_quantity with the view below, using SUM and JOINthis is the SQL Viewitem Name total brand nameB1 item 1 100 brand 1B2 item 2 80 brand 2B3 item 3 40 brand 3B4 item 4 25 brand 4please help me |
|
bandi
Master Smack Fu Yak Hacker
2242 Posts |
Posted - 2012-11-29 : 02:29:23
|
[code]SELECT i.item, name, total, brandnameFROM @tb_item i JOIN @tb_brand b ON i.brand = b.brandJOIN (SELECT item, SUM(quantity) total FROM @tb_quantity GROUP BY item) q ON q.item = i.item[/code]--Chandu |
|
|
chulz90
Starting Member
26 Posts |
Posted - 2012-11-29 : 02:39:58
|
quote: Originally posted by bandi
SELECT i.item, name, total, brandnameFROM @tb_item i JOIN @tb_brand b ON i.brand = b.brandJOIN (SELECT item, SUM(quantity) total FROM @tb_quantity GROUP BY item) q ON q.item = i.item --Chandu
thank's so much chandu |
|
|
bandi
Master Smack Fu Yak Hacker
2242 Posts |
Posted - 2012-11-29 : 04:11:29
|
quote: Originally posted by chulz90 thank's so much chandu
Welcome--Chandu |
|
|
|
|
|