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 ...
随机推荐
- Java 8Lambda之方法引用(Method References)
方法引用分为4类,方法引用也受到访问控制权限的限制,可以通过在引用位置是否能够调用被引用方法来判断.具体分类信息如下: 类型 使用方式 静态方法 ContainingClass::staticMeth ...
- socket 阻塞,同步、I/O模型
1. 概念理解 在进行网络编程时,我们常常见到同步(Sync)/异步(Async),阻塞(Block)/非阻塞(Unblock)四种调用方式: 同步: 所谓同步,就是在发出一个功能调用时, ...
- Java-Runoob:Java StringBuffer 类
ylbtech-Java-Runoob:Java StringBuffer 类 1.返回顶部 1. Java StringBuffer 和 StringBuilder 类 当对字符串进行修改的时候,需 ...
- 前段基础之HTML
HTML 初识 web服务本质 import socket def main(): sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s ...
- 2017百度之星初赛A-1006(HDU-6113)
思路:在图的外面包一圈'0'字符,然后dfs统计'0'字符的个数和'1'字符的个数.结果如下(num0表示0字符的个数,num1表示1字符的个数): num0 == 1 && num1 ...
- Spring表单标签
虽然我们可以使用HTML原生的form表单标签来轻松的写出一个表单,其实我一直都是这样做的,但是使用Spring表单标签可以更方便我们完成例如:验证失败后表单数据的回填功能(虽然你可以使用EL+JST ...
- oracle 存储过程 建表插值等
建表.插值的procedure create or replace procedure CREATE_EMP is v_createsql ); v_insertsql ); begin v_crea ...
- 【BZOJ】1926: [Sdoi2010]粟粟的书架(暴力+主席树)
题目 传送门:QWQ 分析 两道题目 第一问暴力预处理 用$ a[i][j][k] $和$ s[i][j][k] $ 表示从$ (1,1) $ 到 $ (i,j) $ 这个矩形中比k大的数的个数和这些 ...
- fir 窗口设计法
加窗的原因.对于理想的低通滤波器H(exp(jw)),其h(n)是无限长序列.这是可以证明的.因此为了得到有限长的h(n)就需要截断,而这个过程就是加窗.由于h(n)截断即其频率响应就和理想的低通滤波 ...
- 优化笔记:jsyhjkzqxx_D_20140916.gz
有几张表没有权限,所以跑不起来. 目测黄色部分比较坑爹,死了n多脑细胞才看懂,又死了n多脑细胞才改出来.对5034进行了2次扫描,并多次分组排序求和.(分组和排序算法相对来说比较耗性能) 改为只扫描一 ...