197. 上升的温度

作者: 莫小鹏 | 来源:发表于2018-09-23 20:59 被阅读0次

    题目描述

    给定一个 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 |
    +----+
    

    分析

    跟昨天的数据连表,连表的条件是SUBDATE(a.RecordDate,1) = b.RecordDate

    代码

    # Write your MySQL query statement below
    SELECT 
        a.Id 
    from
        Weather a,
        Weather b
    where
        SUBDATE(a.RecordDate, 1) = b.RecordDate and a.Temperature > b.Temperature
    ;
    

    题目链接

    https://leetcode-cn.com/problems/rising-temperature/description/

    相关文章

      网友评论

        本文标题:197. 上升的温度

        本文链接:https://www.haomeiwen.com/subject/hgmqoftx.html