题目链接: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. 初识C++模板元编程(Template Mega Programming)

    前言:毕设时在开源库上做的程序,但是源码看得很晕(当时导师告诉我这是模板元编程,可以不用太在乎),最近自己造轮子时想学习STL的源码,但也是一样的感觉,大致了解他这么做要干什么,但是不知道里面的机制. ...

  2. appium+python自动化41-切换webview时候报chromedriver版本问题

    前言 用appium切换webview的时候报chrome和chromedriver版本的问题:session not created exception: Chrome version must b ...

  3. [Java]一步一步学 Web

    部分内容来自:http://www.cnblogs.com/jinzhenshui/p/3345895.html Java 中的锁写作 synchronized (this) {} .net 中的锁写 ...

  4. kubernetes 学习 service相关

    1:         service有什么用? 直接通过Pod的IP地址和端口号可以访问容器应用,但是pod的IP地址是不可靠的,比如POD出现故障后,有可能在另外一个NOde上启动,这样Pod的IP ...

  5. socket通信循环

    server-----------------#!/usr/bin/env python # encoding: utf-8  # Date: 2018/6/5 import socket phone ...

  6. OpenStack--Cinder(G版)中的volume type

    一.volume type的相关操作 Cinder中的卷类型,是卷的一种标识,各个OpenStack的发行者可根据自身对系统的约束来定义卷类型的使用.G版的Cinder中与卷类型相关的两种资源:typ ...

  7. Tkinter画布-Canvas

    Python - Tkinter画布-Canvas: Canvas是一个长方形的面积,图画或其他复杂的布局.可以放置在画布上的图形,文字,部件,或是帧 Canvas是一个长方形的面积,图画或其他复杂的 ...

  8. PHP5缓存插件

    1.1操作码介绍及缓存原理 当客户端请求一个PHP程序时,服务器的PHP引擎会解析到该PHP程序,并将其变异为特定的操作码文件(OperateCode opcode),这是要执行的PHP代码的一种二进 ...

  9. leetcode341

    数据结构设计类题目,参考网上的代码: /** * // This is the interface that allows for creating nested lists. * // You sh ...

  10. 利用redis限制单个时间内某个mac地址的访问次数

    一.思路 用户mac地址唯一,可以作为redis中的key,每次请求进来,利用ttl命令,判断redis中key的剩余时间,如果大于零,则利用incr进行+1操作,然后再与总的限制次数作对比. 二.代 ...