美文网首页
[Database]197. Rising Temperatur

[Database]197. Rising Temperatur

作者: Reflection_ | 来源:发表于2017-10-22 11:32 被阅读0次

    题目:197. Rising Temperature

    Given a Weather table, write a SQL query to find all dates' Ids with higher temperature compared to its previous (yesterday's) dates.

    +---------+------------+------------------+
    | Id(INT) | Date(DATE) | Temperature(INT) |
    +---------+------------+------------------+
    | 1 | 2015-01-01 | 10 |
    | 2 | 2015-01-02 | 25 |
    | 3 | 2015-01-03 | 20 |
    | 4 | 2015-01-04 | 30 |
    +---------+------------+------------------+
    For example, return the following Ids for the above Weather table:
    +----+
    | Id |
    +----+
    | 2 |
    | 4 |
    +----+

    用SQL的 ** TO_DAYS () **写出日期

    SELECT a.ID
    FROM Weather a, Weather b
    Where a.Temperature > b.Temperature AND TO_DAYS(a.Date) = TO_DAYS(b.Date) + 1;
    

    相关文章

      网友评论

          本文标题:[Database]197. Rising Temperatur

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