你的结果对:应为: no001 豆腐 30 2002-8-3 no001 豆腐 50 2002-8-6 no001 豆腐 60 2002-8-8 no001 豆腐 90 2002-8-9 no002 豆油 20 2002-8-4-----??? no002 豆油 30 2002-8-6 no002 豆油 50 2002-8-9select x.* from @a x,@b y where x.商品编号=y.商品编号 and (select sum(销售数量) from @a where 销售时间>=x.销售时间 and 商品编号=y.商品编号)<=y.销售数量
明白了,但写得不好! select * from a,( select x.商品编号,max(x.销售时间) as 销售时间 from a x,b y where x.商品编号=y.商品编号 and (select sum(销售数量) from a where 销售时间>=x.销售时间 and 商品编号=y.商品编号)>=y.销售数量 group by x.商品编号 ) c where a.商品编号=c.商品编号 and a.销售时间>=c.销售时间
to newly_ignorant: 朋友理解能力不错:)但是好象还需努力呀:) to j9988: thx for your help! good luck!
你测试过?好象不对吧:)有qq?
no001 豆腐 30 2002-8-3
no001 豆腐 50 2002-8-6
no001 豆腐 60 2002-8-8
no001 豆腐 90 2002-8-9 no002 豆油 20 2002-8-4-----???
no002 豆油 30 2002-8-6
no002 豆油 50 2002-8-9select x.* from @a x,@b y where x.商品编号=y.商品编号 and (select sum(销售数量) from @a where 销售时间>=x.销售时间 and 商品编号=y.商品编号)<=y.销售数量
select * from a,(
select x.商品编号,max(x.销售时间) as 销售时间 from a x,b y where x.商品编号=y.商品编号 and (select sum(销售数量) from a where 销售时间>=x.销售时间 and 商品编号=y.商品编号)>=y.销售数量 group by x.商品编号
) c
where a.商品编号=c.商品编号 and a.销售时间>=c.销售时间
朋友理解能力不错:)但是好象还需努力呀:)
to j9988: thx for your help!
good luck!