Phone Numbers
---------------
WorkerId CountryIso-Home Intphn Code-Home
1000 USA 1
1001 IND 2
1002 UK 3
------------
Country_ISO
--------------
Country Iso
United States of America USA
India IND
United Kingdom UK
-----------
Country_PhoneCode
-------------------
Country PhoneCode
United States of America 1
India 2
United Kingdom 3
我想编写Validation sql查询 " Int Phone Code-Home对于给定的CountryISO-Home Code无效。
我试过这种方式..
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)
请帮帮我
答案 0 :(得分:0)
试试这个
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
如果您可以更改数据库结构,请将电话代码移至country_ISO,因为它似乎是1对1匹配,因此从逻辑上看,它可以是ISO表的字段