两个方法:(最大科目)
update A set A.km = (select MAX(B.km) KEEP(DENSE_RANK LAST ORDER BY b.score) FROM b where B.xh = A.xh);
MERGE INTO A
USING (SELECT b.xh
,MAX(b.km) KEEP(DENSE_RANK LAST ORDER BY b.score) AS km
FROM b
GROUP BY b.xh
) b
ON (a.xh=b.xh)
WHEN MATCHED THEN UPDATE
SET a.km = b.km;
最大成绩的科目:
update a
set a.km=(select b.km from (select b.*,row_number()over(partition by b.xh order by b.score desc) rn from b) b
where b.rn=1 and a.xh=b.xh)
where exists (select 1 from from (select b.*,row_number()over(partition by b.xh order by b.score desc) rn from b) b
where b.rn=1 and a.xh=b.xh)
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/16115580/viewspace-1021627/ ,如需转载,请注明出处,否则将追究法律责任。