题目链接: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)的更多相关文章

  1. find the Nth highest salary(寻找第N高薪水)

    Suppose that you are given the following simple database table called Employee that has 2 columns na ...

  2. LeetCode 177. Nth Highest Salary

    https://leetcode.com/problems/nth-highest-salary/description/ Write a SQL query to get the nth highe ...

  3. 【SQL】177. Nth Highest Salary

    Write a SQL query to get the nth highest salary from the Employee table. +----+--------+ | Id | Sala ...

  4. 177. Nth Highest Salary

    问题描述 解决方案 CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT BEGIN declare number int; set numbe ...

  5. Leetcode中的SQL题目练习(二)

    175. Combine Two Tables https://leetcode.com/problems/combine-two-tables/description/ Description Pe ...

  6. 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. +----+ ...

  7. [LeetCode] Nth Highest Salary 第N高薪水

    Write a SQL query to get the nth highest salary from the Employee table. +----+--------+ | Id | Sala ...

  8. LeetCode——Nth Highest Salary

    Write a SQL query to get the nth highest salary from the Employee table. +----+--------+ | Id | Sala ...

  9. [SQL]LeetCode177. 第N高的薪水 | Nth Highest Salary

    Write a SQL query to get the nth highest salary from the Employee table. +----+--------+ | Id | Sala ...

随机推荐

  1. UCML 2.0 For ASP.NET开发平台简介

    互联网时代,我们能跟上网络变革的步伐吗?我们的产品领先于竞争对手吗?我们能够满足日益个性化的客户需求吗? 采用新的软件开发方法是我们的首要选择. 第一个全面支持ASP.NET的应用框架开发平台诞生了— ...

  2. C#如何:启用和禁用自动绑定重定向 (微软)

    https://msdn.microsoft.com/zh-cn/library/2fc472t2.aspx 如何:启用和禁用自动绑定重定向 .NET Framework (current versi ...

  3. ConcurrentLinkedQueue 模拟火车售票过程

    火车票类 public class Ticket { private String NO; // 车票编号 private double price; // 票价 public Ticket(Stri ...

  4. composer包php-amqplib

    php-amqplib官方文档 url:http://www.rabbitmq.com/tutorials/tutorial-one-php.html #测试demo: url: http://**. ...

  5. window 2003 实现多用户远程登录

    1.单击开始->运行,输入gpedit.msc,打开组策略编辑器,找到计算机配置 ->管理模版 -> Windows组件 ->终端服务.把限制连接数量的属性修改成我们需要的数字 ...

  6. node中的ajax提交小例子

    我们看一个HTML5页面中通过AJAX请求的方式获取HTTP服务器返回数据的代码示例.由于我们把服务器的端口指定为1337,并将从端口为80的网站中运行HTML5页面,因此这是一种跨域操作,需要在HT ...

  7. poj 3518 Prime Gap

    Prime Gap Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 7392   Accepted: 4291 Descrip ...

  8. Linux 调优方案--ulimit命令

    可以用ulimit -a 来显示当前的各种用户进程限制.下面把某linux用户的最大进程数设为10000个:     ulimit -u 10240     对于需要做许多 socket 连接并使它们 ...

  9. sql sever数据库常用的执行语句

    --使用master数据库use master --创建数据库文件create database 数据库名字 on( name=, --逻辑名称 filename= .ndf, --数据文件物理路径名 ...

  10. Promise题目

    setTimeout(function () { console.log(1); }, 0) new Promise(function executor(resolve) { console.log( ...