在一次采访中,他们让我写查询“更新具有最大百分比的行”...该列包含studentName,maths,science,percentage
...
请帮我用聚合函数编写更新查询...
答案 0 :(得分:4)
update YourTable
set col1 = 42
where percentage =
(
select max(percentage)
from YourTable
)
答案 1 :(得分:1)
create table dummy (user_id int,name varchar(50),percentage int)
insert into dummy values(1,'Amit',99);
insert into dummy values(2,'Michle',80);
insert into dummy values(3,'Naval',60);
insert into dummy values(4,'Jack',56);
update dummy set percentage='100'
where percentage=(select max(percentage) from dummy)
答案 2 :(得分:0)
;WITH x AS
(
SELECT
studentName, maths, science,
r = RANK() OVER (ORDER BY percentage DESC)
FROM dbo.table_name
)
UPDATE x
SET studentName = studentName + ' - Gold star'
WHERE r = 1;