我最终遇到了一个特殊的问题。我无法找出问题的根本原因。请帮忙。
请通过执行以下脚本来创建表
CREATE TABLE Employee_salary (ID INT,emp_name VARCHAR(50),Salary INT) INSERT INTO Employee_salary VALUES(1,'Dolu',15000) INSERT INTO Employee_salary VALUES(2,'Bolu',15000) INSERT INTO Employee_salary VALUES(3,'Kalia',10000) INSERT INTO Employee_salary VALUES(4,'Bheem',50000) INSERT INTO Employee_salary VALUES(5,'Krishna',40000) INSERT INTO Employee_salary VALUES(6,'Chutki',30000) SELECT * FROM Employee_salary ID emp_name Salary 1 Dolu 15000 2 Bolu 15000 3 Kalia 10000 4 Bheem 50000 5 Krishna 40000 6 Chutki 30000
我想要薪水最高的员工,所以我发现了bwlow查询
SELECT Top 1 emp_name,MAX(salary) from Employee_salary Group by emp_name
我试图找到最低薪水雇员,并尝试通过将“ MAX”更改为“ MIN”来执行以下查询。令人惊讶的是,以下查询无法以任何方式工作。仍然显示“ Bheem,50000”,这是一个错误的答案。谁能告诉我这个问题的原因或原因。
SELECT Top 1 emp_name,MIN(salary) from Employee_salary Group by emp_name
请尝试从最低工资以下查询:
SELECT Top 1 emp_name, salary from Employee_salary order by salary
和
SELECT Top 1 emp_name, salary from Employee_salary order by salary desc
获得最高薪水。
如果有多名雇员的工资相同,请尝试:
SELECT Top 1 WITH TIES emp_name, salary from Employee_salary order by salary desc