0
我有一個產品表,一個價格表和一個pricelist_products表連接它們。有任意數量的價格表和價格表不涵蓋所有產品。我期望選擇所有產品,並將pricelist_products的價格作爲結果中的n列。這是可能的(沒有程序)?我遇到了數據透視查詢,但任意數量的列表似乎並不適合。SQL Server:加入任意數量的列
示例模式:
products
pid | name
----|------
1 | foo
2 | bar
3 | thing
pricelists
lid | name
----|------
1 | internal
2 | external
n | ...
pricelist_products
lid | pid | price
----|-----| ------
1 | 1 | 1.00
1 | 2 | 2.00
2 | 1 | 3.00
2 | 3 | 4.00
期望的結果:
pid name internal external ...n
1 foo 1.00 3.00
2 bar 2.00 -
3 thing - 4.00
聽起來像是對我的報告。 – onedaywhen 2011-06-15 07:36:03