22,210
社区成员
发帖
与我相关
我的任务
分享
select * from
(select row_number() over(partition by a.订单id order by b.StartDate desc) no,*
from 订单表 a,价格表 b where a.订单id=b.订单id) t
where no=1
select a.*,b.* from 价格表 a left join 销售订单表 b on a.ItemCode=b.ItemCode
where not exists(select 1 from 价格表 where ItemCode=a.ItemCode and StartDate>a.StartDate)
select 价格 from 价格表 a left join 销售订单表 b on a.销售订单id = b.id
where not exist
(select 1 from 价格表 c where c.id = a.id and c.datetime>a.datetime )
--举个例子