Question:

Write a SQL query to get the second highest salary from the Employee table.

+----+--------+
| Id | Salary |
+----+--------+
| 1 | 100 |
| 2 | 200 |
| 3 | 300 |
+----+--------+

For example, given the above Employee table, the second highest salary is 200. If there is no second highest salary, then the query should return null.

Analysis:

写一个SQL语句找出Employee表中第二高的年薪,如果没有,则返回null。

我们可以先取出最大的Salary,然后再取出比最大的Salary小的最大Salary。

Answer:

select max(Salary) from Employee
where Salary < (select max(Salary) from Employee);
 

DataBase -- Second Highest Salary的更多相关文章

  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] Department Highest Salary 系里最高薪水

    The Employee table holds all employees. Every employee has an Id, a salary, and there is also a colu ...

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

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

  4. [LeetCode] Second Highest Salary 第二高薪水

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

  5. LeetCode 176 Second Highest Salary mysql,select 嵌套 难度:1

    https://leetcode.com/problems/second-highest-salary/ Write a SQL query to get the second highest sal ...

  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. TSQL Beginners Challenge 1 - Find the second highest salary for each department

    很久以前准备写的系列文章,后来因为懒一直耽搁着,今天突然决定继续下去,于是有了这篇文章,很基础,但很常用.题目描述依然拷贝.简单来说就是找出个个部门薪水排名第二的人,排名相同的要一起列出来. Intr ...

  8. Leetcode 176. Second Highest Salary

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

  9. [SQL]LeetCode176. 第二高的薪水 | Second Highest Salary

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

随机推荐

  1. JavaScript实现图片切换

    页面内容:一个按钮标签  一个Img标签 实现原理:通过修改Img标签的src属性,实现图片的切换 备注:代码中flag变量仅仅用作标记,也可以直接用Img标签的src属性进行判断,不过在判断时候不能 ...

  2. 富文本编辑器 wangEditor.js

    1.引用 wangEditor 相关js  和 css 下载地址:https://files.cnblogs.com/files/kitty-blog/WangEditor.zip 3.页面: < ...

  3. Centos在虚拟机VMware12上的安装

    欢迎评论和更正 虚拟机12的安装 看教程https://blog.csdn.net/yhj19920417/article/details/72891766 centos6.5镜像下载(选minima ...

  4. MySQL实现排名并查询指定用户排名功能,并列排名功能

    MySQL实现排名并查询指定用户排名功能,并列排名功能 表结构: CREATE TABLE test.testsort ( id int(11) NOT NULL AUTO_INCREMENT, ui ...

  5. laravel 基础 --内置函数

    简介 Laravel 自带了一系列 PHP 辅助函数,很多被框架自身使用,如果你觉得方便的话也可以在代码中使用它们. https://laravelacademy.org/post/8967.html ...

  6. Leecode刷题之旅-C语言/python-69x的平方根

    /* * @lc app=leetcode.cn id=69 lang=c * * [69] x 的平方根 * * https://leetcode-cn.com/problems/sqrtx/des ...

  7. 008---re正则模块

    re正则模块 字符串的匹配规则 匹配模式 re.match() re.search() re.findall() re.split() re.sub() 元字符 print('------------ ...

  8. 前端学习webpack

    ### 模块化- 为了保证代码充分解耦,一个大的项目拆分成互相依赖的一个一个的小的模块,最后再通过简单的方式合并在一起- 每一个js文件都可以看成一个单独的模块在node这边(服务器端),提出Comm ...

  9. Lambda方式左连接有Linq方式左连接

    网上查到的直接使用Join+DefaultIfEmpty的方式是错误的,实际生成SQL是两表先内联接,然后再LEFT JOIN.经过查证,参考资料,最终得到如下两种方式的左连接写法: public v ...

  10. 【数据库】 SQLite 语法

    [数据库] SQLite 语法 一 . 创建数据库 1. 只需创建数据库,只需创建文件,操作时将连接字符串指向该文件即可 2. 连接字符串 : data source = FilePath; 不能加密 ...