开发者

Update table without using Cursor

I have data like this

alt text http://img252.imageshack.us/img252/8518/data.png

I want to update minP, maxP and agvP columns on the basis of Id. My desired result is;

alt text http://img20.imageshack.u开发者_Python百科s/img20/2029/updatedu.png

Please help.


Try something like:

update mt
set minp = a.minp,
maxp = a.maxp,
avgp = a.avgp
from mytable mt
join
(select id, min(price) as minp, max(price) as maxp, avg(price) as avgp
from mytable group by id) a on a.id = mt.id
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜