今日SQL题难度:🌟☆☆☆☆☆☆☆☆☆
1、题目要求
- 找出每个部门中薪资最高的员工
- 显示部门ID、部门名称、员工ID、员工姓名以及对应的薪资
2、表和虚拟数据
现有两个表:Employees 和 Departments,记录了员工和部门信息。
CREATE TABLE Departments (DepartmentID INT PRIMARY KEY,DepartmentName NVARCHAR(100)
);CREATE TABLE Employees (EmployeeID INT PRIMARY KEY,EmployeeName NVARCHAR(100),DepartmentID INT,Salary DECIMAL(10, 2)
);
INSERT INTO Departments (DepartmentID, DepartmentName) VALUES
(1, 'HR'),
(2, 'IT'),
(3, 'Finance');INSERT INTO Employees (EmployeeID, EmployeeName, DepartmentID, Salary) VALUES
(1, 'Alice', 1, 50000.00),
(2, 'Bob', 2, 70000.00),
(3, 'Charlie', 2, 80000.00),
(4, 'David', 3, 60000.00),
(5, 'Eve', 3, 55000.00),
(6, 'Frank', 1, 55000.00);
3、查询结果(解法晚上发布)