CREATE DATABASE E_volunteerSy;
USE E_volunteerSy;
CREATE TABLE Participate_In
( V_ID INT(4) PRIMARY KEY,
Ename CHAR(20),
POINTS INT(255),
AName CHAR(20)
);
INSERT INTO Participate_In
values
(1001,'Name1',10,'A'),
(1002,'Name2',3,'A'),
(1003,'Name3',11,'B'),
(1004,'Name4',3,'B'),
(1005,'Name5',4,'B');
如何才能使返回AName A和AName B的最高点的查询更加正确。 AName意味着活动名称。
答案 0 :(得分:2)
您可以使用MAX
和GROUP BY
SELECT AName, MAX(POINTS) AS Points FROM Participate_In GROUP BY AName
答案 1 :(得分:1)
此查询将显示所有活动的最高分
SELECT Aname, MAX(points)
FROM Participate_In
GROUP BY Aname
答案 2 :(得分:0)
这将为每个AName值选择最高记录点数
SELECT *
FROM (
SELECT *, ROW_NUMBER() OVER(PARTITION BY AName ORDER BY POINTS DESC) AS RowNum
FROM Participate_In
) Sub
WHERE RowNum = 1