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

leetcode数据库sql之Rising Temperature

时间:2015-08-04 19:21:49      阅读:177      评论:0      收藏:0      [点我收藏+]

标签:

leetcode原文引用:

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语句如下:

select t2.id from Weather t1 
inner join Weather t2 on 
t1.Temperature < t2.temperature
and 
to_days(t1.Date) = to_days(t2.Date)-1

注意:原来忘了使用to_days函数,导致提交一直说有错误,必须要加上to_days函数!!

版权声明:本文为博主原创文章,未经博主允许不得转载。

leetcode数据库sql之Rising Temperature

标签:

原文地址:http://blog.csdn.net/zkn_cs_dn_2013/article/details/47280075

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