美文网首页
2020-11-14-Mysql(领扣-分组求值)

2020-11-14-Mysql(领扣-分组求值)

作者: 冰菓_ | 来源:发表于2020-11-25 08:03 被阅读0次
    image.png
    with x as 
    (
    select 
    Name, Salary,DepartmentId,
    dense_rank() over(partition by DepartmentId  order by Salary desc)  as result
    from 
    Employee) 
    select 
    Department.Name AS Department ,
    x.Name AS   Employee,
    x.Salary AS Salary
    from
    Department join x on  x.DepartmentId = Department.Id  
    where x.result = 1
    
    image.png
    select s.name as department,t.name as Employee,t.salary from (
    select name,salary,departmentid,
    dense_rank() over(partition by departmentid order by salary desc) as rn 
    from 
    Employee) t
    join department s on t.departmentid = s.id 
    where rn <=3
    

    相关文章

      网友评论

          本文标题:2020-11-14-Mysql(领扣-分组求值)

          本文链接:https://www.haomeiwen.com/subject/qypbbktx.html