leetcode - database - 177. Nth Highest Salary (Oracle)
题目链接:https://leetcode.com/problems/nth-highest-salary/description/
题意:查询出表中工资第N高的值
思路:
1、先按照工资从高到低排序(注意去重)
select distinct Salary from Employee order by Salary desc
2、使用rownum给查询出的数据标注行号
select rownum ro, s.Salary from (select distinct Salary from Employee order by Salary desc)s
3、查询行号>=N并且<=N(即N位)的值,注意在oracle函数中 修改查询出的字段名要用into
CREATE FUNCTION getNthHighestSalary(N IN NUMBER) RETURN NUMBER IS
result NUMBER;
BEGIN
/* Write your PL/SQL query statement below */
select Salary into result from (select rownum ro, s.Salary from (select distinct Salary from Employee order by Salary desc)s) where ro>=N and ro<=N;
RETURN result;
END;
leetcode - database - 177. Nth Highest Salary (Oracle)的更多相关文章
- find the Nth highest salary(寻找第N高薪水)
Suppose that you are given the following simple database table called Employee that has 2 columns na ...
- LeetCode 177. Nth Highest Salary
https://leetcode.com/problems/nth-highest-salary/description/ Write a SQL query to get the nth highe ...
- 【SQL】177. Nth Highest Salary
Write a SQL query to get the nth highest salary from the Employee table. +----+--------+ | Id | Sala ...
- 177. Nth Highest Salary
问题描述 解决方案 CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT BEGIN declare number int; set numbe ...
- Leetcode中的SQL题目练习(二)
175. Combine Two Tables https://leetcode.com/problems/combine-two-tables/description/ Description Pe ...
- leetcode Database3(Nth Highest Salary<—>Consecutive Numbers<—>Department Highest Salary)
一.Nth Highest Salary Write a SQL query to get the nth highest salary from the Employee table. +----+ ...
- [LeetCode] Nth Highest Salary 第N高薪水
Write a SQL query to get the nth highest salary from the Employee table. +----+--------+ | Id | Sala ...
- LeetCode——Nth Highest Salary
Write a SQL query to get the nth highest salary from the Employee table. +----+--------+ | Id | Sala ...
- [SQL]LeetCode177. 第N高的薪水 | Nth Highest Salary
Write a SQL query to get the nth highest salary from the Employee table. +----+--------+ | Id | Sala ...
随机推荐
- wdlinux中apache配置反向代理模块
想要在.htaccess中开启反向代理功能都不行[apache中没有mod_proxy模块] .htaccess 文件内容如下 RewriteEngine On RewriteBase / Rewri ...
- 基于Oracle的EntityFramework的WEBAPI2的实现(三)—— 建立APIController及设置返回类型JSON、XML等
建立普通的ApiControler 右击项目中的controller文件夹·添加·控制器·包含操作的webapi2控制器(使用entity framework),写个名字,如果:Test.然后选择类, ...
- TransportClient操作详解
Elasticsearch JAVA操作有三种客户端: 1.TransportClient 2.JestClient 3.RestClient 还有种是2.3中有的NodeClient,在5.5.1中 ...
- buntu12.10 64位 + android-ndk-r9 编译ffmpeg遇到的问题
android-ndk-r8d/build/core/build-binary.mk:41: *** target file `clean' has both : and :: entries. ...
- java代码---------实现File的目录下创建文本文档
总结:虽然他没教给我们很多,但是他已经很棒了 package com.a.b; import java.io.*; public class dd { public static void main( ...
- centos6.9 x64安装http,php5.6,curl5.29,mysql最后安装zabbix3.4+zabbix客户端
https://www.zabbix.com/documentation/3.4/zh/manual/installation/requirementshttps://www.zabbix.com/d ...
- ETL开源工具kettle学习笔记
一 Kettle配置与部署 参考1:http://www.cnblogs.com/limengqiang/archive/2013/01/16/KettleApply1.html 1.下载kettle ...
- Python if判断语句
a=input('输入你的用户名:') if a == "lilei": print('李磊,等你好久了') elif a == "wanghui": prin ...
- sql之分段统计
sql之分段统计 需求:获取一个县所有家庭人数在1-2人,3-4人,5-6人,6人以上的家庭数的数组 思路:通过CASE WHEN 将 CBFCYSL分组,然后统计数据条数. 语句: SELECT T ...
- C#中的数据格式转换 (未完待更新)
一.string to int int intA = 0;1.intA =int.Parse(str);2.int.TryParse(str, out intA);3.intA = Convert.T ...