上升的温度

时间:2020-03-26
本文章向大家介绍上升的温度,主要包括上升的温度使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

地址:https://leetcode-cn.com/problems/rising-temperature/

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

     示例:
     给定一个 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 |
     +----+
  
`解题思路`

1 使用where

    `select a.id from Weather as a ,Weather as b 
     where 
     datediff(a.RecordDate,b.RecordDate)= 1 and a.Temperature >b.Temperature;
`
     
2 使用join

        `select a.id from Weather as a  join Weather as b on
         datediff(a.RecordDate,b.RecordDate)=1 and a.Temperature>b.Temperature`
    

原文地址:https://www.cnblogs.com/8013-cmf/p/12573027.html