--前三次是指销售日期最前的?
select 商品编码,销售日期,售价
from 销售明细表 a
where(
select count(*) from 销售明细表
where 商品编码=a.商品编码 and(
销售日期<a.销售日期
or
销售日期=a.销售日期 and 销售小票号<=a.销售小票号))<=3
select 商品编码,销售日期,售价
from 销售明细表 a
where(
select count(*) from 销售明细表
where 商品编码=a.商品编码 and(
销售日期<a.销售日期
or
销售日期=a.销售日期 and 销售小票号<=a.销售小票号))<=3
select 商品编码,销售日期,售价
from 销售明细表 a
where(
select count(*) from 销售明细表
where 商品编码=a.商品编码 and(
销售日期>a.销售日期
or
销售日期=a.销售日期 and 销售小票号>=a.销售小票号))<=3
1:將top 1 商品编码,max(销售日期) 插入到一個臨時表 #t group by 商品编码
2:將top 1 商品编码,max(销售日期) 插入到一個臨時表 #t where not exists (select * from #t where ....)
group by 商品编码
3:同2.
?????????ˋ??
select 商品编码,销售日期,售价
from 销售明细表 a
where(
select count(*) from 销售明细表
where 商品编码=a.商品编码 and(
销售日期<=a.销售日期 --这样改好像不是可以吗?
and 销售小票号<=a.销售小票号))<=3