[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;

你可能感兴趣的:([Database]197. Rising Temperature)