zoukankan      html  css  js  c++  java
  • Mysql习题

    编写一个 SQL 查询,获取 Employee 表中第二高的薪水(Salary) 。

    +----+--------+
    | Id | Salary |
    +----+--------+
    | 1 | 100 |
    | 2 | 200 |
    | 3 | 300 |
    +----+--------+
    例如上述 Employee 表,SQL查询应该返回 200 作为第二高的薪水。如果不存在第二高的薪水,那么查询应返回 null。

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

    来源:力扣(LeetCode)
    链接:https://leetcode-cn.com/problems/second-highest-salary
    著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。

    ifnull(A,B)语句,如果A不为空,则返回A,否则返回B。
    limit x,y 从返回的第x+1条语句开始,返回y条
    select ifnull((select distinct Salary from Employee order by Salary desc limit 1,1),null) as SecondHighestSalary;

    给定一个 Weather 表,编写一个 SQL 查询,来查找与之前(昨天的)日期相比温度更高的所有日期的 Id。

    +---------+------------------+------------------+
    | Id(INT) | RecordDate(DATE) | Temperature(INT) |
    +---------+------------------+------------------+
    | 1 | 2015-01-01 | 10 |
    | 2 | 2015-01-02 | 25 |
    | 3 | 2015-01-03 | 20 |
    | 4 | 2015-01-04 | 30 |
    +---------+------------------+------------------+
    例如,根据上述给定的 Weather 表格,返回如下 Id:

    +----+
    | Id |
    +----+
    | 2 |
    | 4 |
    +----+

    来源:力扣(LeetCode)
    链接:https://leetcode-cn.com/problems/rising-temperature
    著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。

    1 # Write your MySQL query statement below
    2 select a.Id from Weather as a, Weather as b where a.Temperature > b.Temperature && datediff(a.RecordDate, b.RecordDate) = 1; 
  • 相关阅读:
    文件内容排名算法,输入排名函数,返回排名后的文件名
    线段树做大数据排序
    给字符排序-基类排序二分查找-JavaScript
    后缀数组、名次数组-JavaScript
    二分查找法、二分去重排序法,返回最接近的位置和实际位置
    用四叉树对图像分类,获取tag和key
    Linux显示所在Git分支
    Linux中设置Git显示颜色
    屏蔽网页广告
    tf.add_to_collection,tf.get_collection简介
  • 原文地址:https://www.cnblogs.com/letlifestop/p/11603327.html
Copyright © 2011-2022 走看看