select identity(int,1,1) id,* into #临时表 from T_tempselect *,(select sum(case when style>0 then quantity else -quantity end) from #临时表 where fitem=tem.fitem and id<=tem.id ) totalq from #临时表 tem
select identity(int,1,1) id,* into #临时表 from T_tempselect *,(select sum(case when style>0 then quantity else -quantity end) from #临时表 where fitem=tem.fitem and id<=tem.id ) totalq from #临时表 tem
select identity(int,1,1) id,* into #临时表 from T_tempselect *,(select sum(case when style>0 then quantity else -quantity end) into T_totalq from #临时表 where fitem=tem.fitem and id<=tem.id ) totalq from #临时表 temdrop table #临时表
select identity(int,1,1) id,* into #临时表 from T_tempselect *,(select sum(style*quantity) from #临时表 where fitem=tem.fitem and id<=tem.id ) totalq from #临时表 tem