Sql 如果一列对其他表中的另一列无效 我有三张桌子
我想为其编写验证sql查询 “Int Phone Code Home对于给定的CountryISO Home代码无效 我试过这样做Sql 如果一列对其他表中的另一列无效 我有三张桌子,sql,sql-server,sqlcode,Sql,Sql Server,Sqlcode,我想为其编写验证sql查询 “Int Phone Code Home对于给定的CountryISO Home代码无效 我试过这样做 SELECT WorkerId FROM PhoneNumbers a, Country_PhoneCode b WHERE IntPhnCode - Home != (SELECT PhoneCode FROM Country_PhoneCode i,
SELECT WorkerId
FROM PhoneNumbers a,
Country_PhoneCode b
WHERE IntPhnCode - Home != (SELECT PhoneCode
FROM Country_PhoneCode i,
Country_ISO j
WHERE i.Country = j.Country)
请帮帮我试试这个
select WorkerId
from PhoneNumbers a
join Country_ISO b on b.iso=a.CountryIso-Home
join country_phoneCode c on c.coutry=b.country
where c.PhoneCode <> a.Intphn Code-Home
选择WorkerId
从电话号码a
在b.ISO=a.CountryIso-Home上加入国家/地区
在c.coutry=b.country上加入国家/地区\电话码c
其中c.PhoneCode a.Intphn代码Home
- JOIN Country_ISO将工人与其国家匹配
- JOIN country_phoneCode获取该国家/地区的电话代码
- 在代码不匹配的情况下,报告工人的WHERE子句
select WorkerId
from PhoneNumbers a
join Country_ISO b on b.iso=a.CountryIso-Home
join country_phoneCode c on c.coutry=b.country
where c.PhoneCode <> a.Intphn Code-Home