34,594
社区成员
发帖
与我相关
我的任务
分享
--这样更直观
select * from 商品采购记录表 c ,
(select 商品编号,采购日期
from 商品采购记录表 a
where not exists (select 1 from 商品采购记录表 b
where a.商品编号=b.商品编号 and b.采购日期>a.采购日期)
group by 商品编号,采购日期 having count(*)>1) tb
where c.商品编号=tb.商品编号 and c.采购日期=tb.采购日期
--执行一下就知道相同编号相同最新采购日期的重复记录是那些了
select 商品编号,采购日期
from 商品采购记录表 a
where not exists (select 1 from 商品采购记录表 b
where a.商品编号=b.商品编号 and b.采购日期>a.采购日期)
group by 商品编号,采购日期 having count(*)>1
select top 1 * from 采购记录表 a where not exists(select 1 from 采购记录表 where 商品编号=a.商品编号 and 采购日期>a.采购日期)
select * from 采购记录表 a where not exists(select 1 from 采购记录表 where 商品编号=a.商品编号 and 采购日期>a.采购日期)
select *
from 商品采购记录表 a
where not exists (select 1 from 商品采购记录表 b
where a.商品编号=b.商品编号 and b.采购日期>a.采购日期)