[Database]197. Rising Temperature

题目:197. Rising Temperature

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的 ** TO_DAYS () **写出日期

SELECT a.ID
FROM Weather a, Weather b
Where a.Temperature > b.Temperature AND TO_DAYS(a.Date) = TO_DAYS(b.Date) + 1;
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 183. Customers Who Never Order Problem Suppose that a web...
    olivia_ong阅读 394评论 0 0
  • sqlmap用户手册 说明:本文为转载,对原文中一些明显的拼写错误进行修正,并标注对自己有用的信息。 ======...
    wind_飘阅读 2,129评论 0 5
  • http://192.168.136.131/sqlmap/mysql/get_int.php?id=1 当给sq...
    xuningbo阅读 10,479评论 2 22
  • 1. Java基础部分 基础部分的顺序:基本语法,类相关的语法,内部类的语法,继承相关的语法,异常的语法,线程的语...
    子非鱼_t_阅读 31,825评论 18 399
  • 今天0501的晨读资料是“聪明人迅速提升交流质量、有效帮助他人”,参考书目《高绩效教练》,总的来说就是如何有效开导...
    Miss乔_阅读 544评论 3 3