Oracle:函数Last,First的用法

oracle 专栏收录该内容
23 篇文章 0 订阅

创建一个简单的员工信息表

Create Table EmployeeInfo (CODE Number(3) Not Null,EmployeeName varchar2(15),DepartmentID Number(3),Salary NUMBER(7,2),
Constraint PK_EmployeeInfo Primary Key (CODE));

--CODE 编码    --EmployeeName 员工姓名 --DepartmentID 员工所属部门编码 Salary 工资

Select * From EMPLOYEEINFO

Oracle:函数Last,First的用法 - ZbrSky - ZbrのBlog

SQL语句:

Select DEPARTMENTID,
           Min(SALARY) Keep (DENSE_RANK First Order By SALARY Desc) "FIRST",
           Max(SALARY) Keep (DENSE_RANK Last Order By SALARY Desc) "LAST"
From EMPLOYEEINFO Group By DEPARTMENTID

--此语句的返回结果是每个部门最高的工资和最低的工资:

Oracle:函数Last,First的用法 - ZbrSky - ZbrのBlog

SQL语句:

Select EmployeeName,DEPARTMENTID,SALARY,
           Min(SALARY) Keep (DENSE_RANK First Order By SALARY Desc) OVER (Partition By DEPARTMENTID)  "FIRST",
           Max(SALARY) Keep (DENSE_RANK Last Order By SALARY Desc) OVER (Partition By DEPARTMENTID) "LAST"
From EMPLOYEEINFO Group By DEPARTMENTID,SALARY,EmployeeName

--此语句返回结果比上述查询更详细,增加了员工姓名:

Oracle:函数Last,First的用法 - ZbrSky - ZbrのBlog


  • 0
    点赞
  • 0
    评论
  • 1
    收藏
  • 扫一扫,分享海报

参与评论 您还未登录,请先 登录 后发表或查看评论
©️2022 CSDN 皮肤主题:大白 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值