select AA.GoodsID from
(
select A.GoodsID,A.SerNum from
(select * from VStock where SerNum is not null) A
left join InStorage_Record B on (A.GoodsID=B.GoodsID and A.SerNum=B.ISRSerNum)
) AA
where not exists
(select 1 from AA C where AA.GoodsID=C.GoodsID and AA.SerNum=C.SerNum and AA.ISNDate>C.ISNDate
having count(1)>0)
因为AA对象名属于from中的一个子查询,在where中可以直接引用,但是在其下的子查询中无法使用,这个时候可以采取with as结构解决。有关该结构的详细使用可看下面文章:http://blog.youkuaiyun.com/xueminxu/article/details/8132074
sql子查询中引用无效对象名
最新推荐文章于 2023-06-07 23:33:07 发布