码疯窝

LeetCode 每日一题 — Rising Temperature

2015/04/07 04:05:42    分类: 日志连载    0人评论 次浏览

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 |
+----+

分析: 此题难道又有降低之嫌.

SELECT t1.Id
FROM Weather t1
INNER JOIN Weather t2
ON t2.Date = DATE_SUB(t1.Date, INTERVAL 1 DAY)
WHERE t1.Temperature > t2.Temperature
继续查看有关 日志连载的文章

0个访客评论