码迷,mamicode.com
首页 > 数据库 > 详细

leetcode上升的温度--oracle同表比较

时间:2019-02-15 13:30:19      阅读:193      评论:0      收藏:0      [点我收藏+]

标签:code   日期类型   you   stat   因此   where   and   tco   int   

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

方法:

oracle 日期类型的直接使用+1来表示日期差。

因此,我们可以通过将 weather 与自身比较

/* Write your PL/SQL query statement below */
select a.Id from Weather a,Weather b where a.RecordDate=b.RecordDate+1 and a.Temperature>b.Temperature

 

leetcode上升的温度--oracle同表比较

标签:code   日期类型   you   stat   因此   where   and   tco   int   

原文地址:https://www.cnblogs.com/raychou1995/p/10383054.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!