日期:2014-05-17 浏览次数:20537 次
with TB(PROD,PRODQTY,OPR,QTY ,DATE)as
(
select 'A01',100,'A',5,'2012-01-01' union all
select 'A01',100,'B',25,'2012-01-02' union all
select 'A01',100,'C',35,'2012-01-03' union all
select 'A01',100,'D',15,'2012-01-04' union all
select 'A01',100,'E',15,'2012-01-05' union all
select 'A01',100,'f',10,'2012-01-06' union all
select 'A01',100,'g',12,'2012-01-07' union all
select 'A02',50,'Aa',5,'2012-02-01' union all
select 'A02',50,'Ba',10,'2012-02-02' union all
select 'A02',50,'Ca',20,'2012-02-03' union all
select 'A02',50,'Da',16,'2012-02-04' union all
select 'A02',50,'Ea',15,'2012-02-05' union all
select 'A02',50,'fa',10,'2012-02-06' union all
select 'A02',50,'ga',12,'2012-02-07'
)
select * from tb where prod+date in
(select prod+date from
(select row_number() over(partition by a.prod order by a.prod)number,a.PROD,a.PRODQTY