设为首页 加入收藏

TOP

leetcode数据库sql之RisingTemperature
2015-11-21 02:04:04 来源: 作者: 【 】 浏览:0
Tags:leetcode 数据库 sql RisingTemperature

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函数!!
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇1064-You have an error in your .. 下一篇sql数据类型总结

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: