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 query should return 200 as the second highest salary. If there is no second highest salary, then the query should return null.

+---------------------+
| SecondHighestSalary |
+---------------------+
| 200 |
+---------------------+

思路为先把最大的选出来, 然后把不等于之前的最大的, 最大的salary选出来即可.

SELECT max(Salary) as SecondHighestSalary FROM Employee WHERE Salary NOT IN (SELECT max(Salary) FROM Employee) 

[LeetCode] 176. Second Highest Salary_Easy tag: SQL的更多相关文章

  1. 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 ...

  2. [LeetCode] 627. Swap Salary_Easy tag: SQL

    Given a table salary, such as the one below, that has m=male and f=female values. Swap all f and m v ...

  3. Leetcode 176. Second Highest Salary

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

  4. [LeetCode] 619. Biggest Single Number_Easy tag: SQL

    Table number contains many numbers in column num including duplicated ones.Can you write a SQL query ...

  5. [LeetCode] 620. Not Boring Movies_Easy tag: SQL

    X city opened a new cinema, many people would like to go to this cinema. The cinema also gives out a ...

  6. [LeetCode] 196. Delete Duplicate Emails_Easy tag: SQL

    Write a SQL query to delete all duplicate email entries in a table named Person, keeping only unique ...

  7. LeetCode 176. Second Highest Salary (第二高的薪水)

    题目标签: 题目给了我们一个工资表,让我们返回第二高的工资. 利用Max,把第一高的工资找到,然后利用 NOT IN,去找到第二高的工资. Java Solution: Runtime:  153ms ...

  8. [LeetCode] 584. Find Customer Referee_Easy tag: SQL

    Given a table customer holding customers information and the referee. +------+------+-----------+ | ...

  9. [LeetCode] 603. Consecutive Available Seats_Easy tag: SQL

    Several friends at a cinema ticket office would like to reserve consecutive available seats.Can you ...

随机推荐

  1. 【linux系列】centos7配置桥接模式静态IP

    一.设置桥接模式 VMware->Edit->Virtual Network Edit 二.查看物理机的ip地址 三.根据物理机的ip地址,设置linux虚拟机的ip地址 四.网络重启 五 ...

  2. linux下文件描述符的介绍

    当某个程序打开文件时,操作系统返回相应的文件描述符,程序为了处理该文件必须引用此描述符.所谓的文件描述符是一个低级的正整数.最前面的三个文件描述符(0,1,2)分别与标准输入(stdin),标准输出( ...

  3. mac Intellij Idea Tmocat 启动报 Error running Tomcat: /conf/Catalina

    原因:主要是tomcat下Catalina目录没有权限导致,将其设置读写权限即可 如果在刚刚启动tomcat时出现以下问题:Error running Tomcat 8.5.31: Error cop ...

  4. LeetCode 16 3Sum Closest (最接近target的3个数之和)

    题目链接 https://leetcode.com/problems/3sum-closest/?tab=Description     Problem : 找到给定数组中a+b+c 最接近targe ...

  5. 使用私钥.pem和SecureCRT登陆linux系统

    将密钥上传到一台自己的linux主机,下面举例文件名为 key.pemchmod 600 key.pem改写密钥格式为 OpenSSH,如果询问passphrase可以留空(直接回车)ssh-keyg ...

  6. VUE单独页面body css设置

    使用created周期用JS来处理BODY的样式 export default { beforeCreate: function () { document.getElementsByTagName( ...

  7. 关于kvm虚拟机的克隆方法总结

    kvm虚拟机的克隆分为两种情况,第一种kvm宿主机上对虚拟机直接克隆 第二种通过复制配置文件与磁盘文件的虚拟机复制克隆(适用于异机的静态迁移). 现笔者将分别两种kvm虚拟机克隆的的详细操作过程都记录 ...

  8. python操作数据库PostgreSQL

    1.简述 python可以操作多种数据库,诸如SQLite.MySql.PostgreSQL等,这里不对所有的数据库操作方法进行赘述,只针对目前项目中用到的PostgreSQL做一下简单介绍,主要包括 ...

  9. PyCharm 4.0.4 开启代码自动补全

    目前在使用的PyCharn 版本为4.0.4,在使用的过程中无法使用代码补全功能,经过Google 搜索只需要修改两处即可实现代码补全 1 选择File-Setting-Inspections 找到对 ...

  10. SQL语句的执行过程

    1.语法校验 如果在SQL计划缓存中没有对应的执行计划,服务器首先会对用户请求的SQL语句进行语法效验,如果有语法错误,服务器会结束查询操作,并用返回相应的错误信息给调用它的应用程序. 注意:此时返回 ...