我想转换此查询:
SELECT *
FROM myTable
WHERE dateCreated = (
SELECT MAX(dateCreated)
FROM myTable
)
AND duty IS NULL
AND CompanyPayingId IN
(43081 ,43082 ,43084 ,43085)
从in
更改为Exists
查询(由于效果):
但是我在转换代码时遇到问题,因为我认为我必须复制 where 子句......
如何转换此代码?
答案 0 :(得分:1)
我可以这样做:
create table num(idn int)
insert into num values(43081) ,(43082),(43084) ,(43085)
select * from num
SELECT *
FROM myTable m inner join num n
ON m.dateCreated = (SELECT MAX(dateCreated) FROM myTable)
AND m.duty IS NULL
AND m.CompanyPayingId=n.num