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 |
|
kazuni
Starting Member
2 Posts |
Posted - 2012-03-15 : 13:48:03
|
| [font=Lucida Console]Hi all, I have a question with regards to joining table and display them. The table schema is as follows:trades--------------------------------------------trade_id trade_name trade_country--------------------------------------------T1 tr1 sgpT2 tr2 phiT3 tr3 thaT4 tr4 hkgtrade_article--------------------------------------------trade_id trade_article order_id customer--------------------------------------------T1 AR1 ORD1 CUST1 T1 AR1 ORD2 CUST2T1 AR2 ORD1 CUST1T1 AR3 ORD3 CUST3 T2 AR1 ORD4 CUST4T2 AR2 ORD5 CUST1T4 AR3 ORD6 CUST5trade_article_size--------------------------------------------order_id article article_size customer total_qty--------------------------------------------ORD1 AR1 SZ1 CUST1 13ORD1 AR1 SZ2 CUST1 10ORD1 AR2 SZ1 CUST1 10ORD2 AR1 SZ1 CUST2 20ORD2 AR1 SZ2 CUST2 10ORD6 AR3 SZ1 CUST5 10 ORD6 AR3 SZ2 CUST5 1ORD6 AR3 SZ3 CUST5 17ORD6 AR3 SZ4 CUST5 20......I want to have an aggregated view that loosk like this:trade_country trade_id trade_name customer total_qty----------------------------------------------------sgp T1 tr1 CUST1 33sgp T1 tr1 CUST2 30hkg T4 tr4 CUST5 48How do i go about joining those tables?(the result table is something like,a customer in a trade meeting can have multiple article with different sizes, we want their sum of total_qty of all articles in that order of a trade meeting to display.)if i am not clear, i can perhaps explain a bit more...Thanks in advance![/font] |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
kazuni
Starting Member
2 Posts |
Posted - 2012-03-15 : 14:25:10
|
| I've got something like...SELECT distinct trades.trade_id, trades.trade_country, trades.trade_name, trade_article.customer, *(sum(select total_qty from trade_article_size))*FROM trades INNER JOIN trade_article ON trades.trade_id = trade_article.trade_idINNER JOIN trade_article_size ON trade_article.order_id = trade_article_size.order_idsomething like that... the ones annotated with the asterisks (*) are the part where i am not sure.. I think i am confused in some way. |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
|
|
|
|
|