我有这样的数据
alt text http://img252.imageshack.us/img252/8518/data.png
我想在Id的基础上更新minP,maxP和agvP列。我想要的结果是;
alt text http://img20.imageshack.us/img20/2029/updatedu.png
请帮忙。
答案 0 :(得分:4)
尝试类似:
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