0
我有表「Table_Codes」在我的SQL Server數據庫如何從多個表中選擇附加條件?
Code | Description | Owner | Location
A202 SomeDescr1 Owner1 M-3
B301 SomeDescr2 Owner2 M-3
C898 SomeDescr3 Owner3 M-2
B744 SomeDescr4 Owner4 M-3
V123 SomeDescr5 Owner5 M-3 - code is not define in second table
我也有表「Table_Stock」
Code | Qty | DC
A202 10 M-3
B301 12 M-2 !-not the same location like in 1st table for this code
C898 90 M-2
B744 120 M-3
我無法建立正確的查詢從該表中選擇下一個結果:
Code | Qty(Location=DC) | Qty on alternate DC (Location from 1st table <> DC)
A202 10 0
B301 0 12
C898 90 0
B744 120 0
V123 Not in stock Not in stock
我可以通過使用輔助表。但我想知道如何通過使用單個SELECT查詢來做到這一點?
如果您有> 1個備用DC,會發生什麼情況?你把它們加在一起嗎? – FJT
是的。如果我有超過1個備用DC,我應該在第三個字段中總結數量 – mbigun