[Database]197. Rising Temperatur
2017-10-22 本文已影响0人
Reflection_
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;