update tablename
set d=d.v_c
from (select min(a) v_a,b,sum(c) v_c from tablename group by b) d
where tabkebane.a=d.v_a and tablename.b=d.b
这是在sql server里面的方法
set d=d.v_c
from (select min(a) v_a,b,sum(c) v_c from tablename group by b) d
where tabkebane.a=d.v_a and tablename.b=d.b
这是在sql server里面的方法
from (select min(A) minA,B,sum(C) sumC from TableName group by B) tt
where TableName.A = tt.minA;
而且還是一樣.
:)BTW:wwl007,你的那個SQL好像不能再优化了.要我也是那麼寫.
from (select min(A) minA,B,sum(C) sumC from TableName group by B) tt --從按B分組的結果集tt中
where TableName.A = tt.minA and TableName.B = tt.B; --關聯minA是min(A)的別名,sumC是sumC的別名.
tt是select min(A) minA,B,sum(C) sumC from TableName group by B這樣一個結果集的別名.