任务是“编写一个SQL查询以按职务分类计算员工的最高工资。(输出显示别名)。
创建了两个表,Employee和Job_Title。 Employee表由Salary组成,而Job_Title表由作业分类组成,例如'Manager'。
我所显示的当前代码,该分类中具有最高工资的员工,但Alias未显示。它只显示该员工的所有信息。
这是我的代码:
SELECT *
FROM Employee
WHERE Salary IN (
SELECT MAX(Salary) AS 'Maximum_Salary_Class'
FROM Employee
WHERE JobID IN ( SELECT JobID
FROM Job_Title_Table_
WHERE Job_Classification = 'Manager' ) );
答案 0 :(得分:0)
试试这个。
;with cte as
(
select E.*,J.Job_Classification,Dense_RAnk() over(partition by J.Job_Classification order by E.Salary) as DenseRank
from Employee E
inner join Job_Title J on E.JobID = J.JobID
)
select * from cte
where DenseRank = 1
我试图了解你的目的。 如果我没弄错,请告诉我。
答案 1 :(得分:0)
这样的事情:
select t.Job_Classification, max(e.salary) as 'Maximum_Salary_Class'
from Employee e join Job_Title_Table_ t on e.JobID = t.JobId
group by t.Job_Classification;
答案 2 :(得分:-1)
我想你想得到这个
SELECT E.*,Job_Classification
FROM Employee
,(
SELECT J.JobID,J.Job_Classification,MAX(Salary) AS 'Maximum_Salary_Class'
FROM Employee AS E
,Job_Title_Table_ AS J
WHERE E.JobID = J.JobID
AND Job_Classification = 'Manager'
GROUP BY J.JobID,J.Job_Classification
) AS EJ
WHERE E.JobID = EJ.JobID
AND Salary = Maximum_Salary_Class