2010-06-28 44 views
2

我想建立一個連接,這樣下面的僞代碼將適用加入其中指定列取決於結果

SELECT * FROM client_rates cl, languages l 

IF cl.Language is numeric  // i.e. is not a specific language 
    join condition = WHERE cl.Language = l.category 
ELSE 
    join condition = WHERE cl.Language = l.Language 

是否有可能實現這一目標只是(我的)SQL?

有這些表中其他列,但相關的有如下:

client_rates(CompanyID,語言率)

語言(語言,類別)

在client_rates中,有時Language是特定的語言,但有時它是針對某個類別的。例如,對於客戶端80,法語費率和英語費率都屬於第1類語言,但對於某些客戶端,僅有類別1,2和3的費率。3

回答

1

您能否使用一個聯盟?所以基本上做到像

SELECT * FROM client_rates cl, languages l join condition = WHERE cl.Language = l.category and cl.Language is numeric 
UNION 
SELECT * FROM client_rates cl, languages l join condition = WHERE cl.Language = l.Language and cl.Language is not numeric 

這應該工作

0

嘗試是這樣的

SELECT * FROM client_rates as cl inner join languages as l 
on 
(cl.Language is numeric and cl.Language = l.category 
or 
cl.Language is not numeric and cl.Language = l.Language 
)