zoukankan      html  css  js  c++  java
  • LeetCode

          题目大概的意思是选出每个Department里工资最高的人的信息并组成相应的表信息

         

          有几个值得注意的地方:1)使用group by语句时,前面的select语句后面的内容只能有两种情况一种是group by后面的属性,另一种是聚集函数

                                         2)在选取最大Salary时必须使用e1.Salary=e2.Salary and e1.DepartmentId=e2.DepartmentId两个条件,要不然会有重复。

           基于这些考虑可以使用派生表查询来找出最大Salary,然后与Department表做自然连接。(最后的升序还是降序无所谓)

         

    select dep.Name as Department, pans.Name as Employee, 
    pans.Salary as Salary
    from Department dep, (
    select e1.* from
    Employee e1, (select DepartmentId, max(Salary) as Salary
    from Employee group by DepartmentId) e2
    where e1.Salary=e2.Salary and e1.DepartmentId=e2.DepartmentId
    ) pans
    where dep.Id=pans.DepartmentId
    order by pans.Salary desc;
    

          

  • 相关阅读:
    矿Mac必备软件
    PHP第六课 使用方法数组
    I/O概述和审查操作
    应用程序配置文件
    他毕业两年,博客一年,时间
    苹果公司的回复
    CImage类的介绍与使用
    数据库移植遇到的问题
    MP算法和OMP算法及其思想
    ROR 环境的 搭建
  • 原文地址:https://www.cnblogs.com/wxisme/p/4442855.html
Copyright © 2011-2022 走看看