2014-04-28 106 views
0

我有這個疑問:顯示價格沒有消除產品

select ItemName,FrgnName,OnHand,Price as Regular_Price from ITM1, OITM 
where exists 
(select null from OSCN 
where oitm.ItemCode=oscn.ItemCode 
and itm1.ItemCode=oscn.ItemCode 
and oscn.CardCode='test' 
and itm1.PriceList=2) 

這個查詢來獲取所有鏈接到了一定的客戶與正常價格(7個產品)的產品。
現在我想添加第四個表(sprecial_prices表),它只有6個產品以特殊的價格爲這個客戶。
的問題是,如果我的special_price表添加到查詢我的結果將是6個產品,我想顯示所有客戶與兩個價格的項目,即使他們中的一個是0
謝謝

回答

1

我想想你的查詢可以重新寫在SQL92語法是這樣的:

select 
    i.ItemName,FrgnName,o.OnHand,i.Price 
from 
    ITM1 i 
    inner join OITM o on i.ItemCode = o.ItemCode 
    inner join OSCN os on o.ItemCode = os.ItemCode 
where 
    o.CardCode = 'test' 
    and i.PriceList = 2 

要添加你想使用左4表連接,使所有記錄都顯示出來,即使有在第4個表中沒有的結果:

select 
    i.ItemName,FrgnName,o.OnHand,i.Price 
from 
    ITM1 i 
    inner join OITM o on i.ItemCode = o.ItemCode 
    inner join OSCN os on o.ItemCode = os.ItemCode 
    left join special_price sp on o.ItemCode = sp.ItemCode --or whatever column joins to special_price 
where 
    o.CardCode = 'test' 
    and i.PriceList = 2 
+0

謝謝你的回答,但你選擇i.ItemName,FrgnName,OnHand,價格從ITM1,只有價格存在於此表中 名稱,一手在OITM表中存在不是ITM1 我試過但不工作! – Sam

+1

@Samira你會得到什麼錯誤/輸出? –

+0

您沒有指定哪個列與哪個表一起使用,所以我放棄了這些別名。請指定你的錯誤。 – paqogomez