日期:2014-05-18 浏览次数:20422 次
--原始数据:@1 declare @1 table(dalei int,xiaolei int) insert @1 select 1,11 union all select 1,12 union all select 1,13 union all select 2,12 union all select 2,13 union all select 3,11 union all select 3,12 union all select 3,14 --原始数据:@2 declare @2 table(cinvcode int,iquantity int) insert @2 select 11,100 union all select 12,200 union all select 13,200 union all select 14,200 select *,cn=cast(null as int) into #T from @1 declare @dalei int declare cur_dalei cursor for select dalei from #T group by dalei open cur_dalei fetch next from cur_dalei into @dalei while @@fetch_status=0 begin update #T set cn=(select min(b.iquantity) from #T a,@2 b where a.dalei=@dalei and a.xiaolei=b.最大的值所在行的数据