在一次采访中,他们要求我编写查询“更新具有最大百分比的行”......该列由studentName,maths,science,percentage
......
请帮助我使用聚合函数编写更新查询...
在一次采访中,他们要求我编写查询“更新具有最大百分比的行”......该列由studentName,maths,science,percentage
......
请帮助我使用聚合函数编写更新查询...
update YourTable
set col1 = 42
where percentage =
(
select max(percentage)
from YourTable
)
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)
;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;