我在 Oracle 中有一个表,如下所示
CREATE TABLE Employees(EmpId INT,
EmpName VARCHAR2(30),
Designation VARCHAR2(30),
Salary INT);
我在表格中插入了如下行
INSERT ALL
INTO Employees(EmpId, EmpName, Designation, Salary)VALUES(101, 'Scott', 'Clerk', 2500)
INTO Employees(EmpId, EmpName, Designation, Salary)VALUES(102, 'Mac', 'Manager', 5000)
INTO Employees(EmpId, EmpName, Designation, Salary)VALUES(103, 'Steave', 'Clerk', 1500)
INTO Employees(EmpId, EmpName, Designation, Salary)VALUES(104, 'John', 'Clerk', 1500)
INTO Employees(EmpId, EmpName, Designation, Salary)VALUES(105, 'Jack', 'Analyst', 2500)
INTO Employees(EmpId, EmpName, Designation, Salary)VALUES(106, 'Paul', 'Manager', 4500)
INTO Employees(EmpId, EmpName, Designation, Salary)VALUES(107, 'Ryan', 'Clerk', 1250)
INTO Employees(EmpId, EmpName, Designation, Salary)VALUES(108, 'Phillipe', 'Analyst', 3150)
INTO Employees(EmpId, EmpName, Designation, Salary)VALUES(109, 'Clark', 'Clerk', 1200)
INTO Employees(EmpId, EmpName, Designation, Salary)VALUES(110, 'Arnold', 'Clerk', 1100)
SELECT * FROM dual;
以下是表格的简短概述
现在我想按以下名称分组收入最高的人
EmpName Designation Salary
Phillipe Analyst 3150
Scott Clerk 2500
Mac Manager 5000
我想要 empName、Designation 和 max Salary by designation。
我尝试了以下查询,但它带来了所有记录
SELECT EmpName, Designation, max(Salary) AS msal
FROM Employees
GROUP BY Designation, EmpName
ORDER BY Designation, msal DESC
谢谢您的回复