频道栏目
首页 > 资讯 > SQL Server > 正文

leetcode数据库sql之RisingTemperature

15-08-05        来源:[db:作者]  
收藏   我要投稿

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函数!!
相关TAG标签
上一篇:MySQL初学者入门教程
下一篇:合服测试(二)
相关文章
图文推荐

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训 | 举报中心

版权所有: 红黑联盟--致力于做实用的IT技术学习网站