我想设置一个连接,以便应用以下伪代码
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中,有时语言是特定语言,但有时它属于某个类别。例如,对于客户80,有法语的费率和英语的费率,它们都是1类语言,但对于某些客户,只有1,2和3类的费率
答案 0 :(得分:1)
你能使用UNION吗?所以基本上就像
一样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
那应该有用
答案 1 :(得分: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
)