开发者

Update table without using Cursor

开发者 https://www.devze.com 2022-12-10 13:18 出处:网络
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;

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

精彩评论

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