题目链接:点击打开链接
题目大意:略。
解题思路:考察点对时间函数的使用,有些人上来就是 “w1.recordDate - w2.recordDate = 1”,这样做最后一个用例通不过,因为跨月份呢,一首凉凉送给你
- 解决方案(1):DATEDIFF 函数
- 解决方案(2):TIMESTAMPDIFF 函数
- 解决方案(3):ADDDATE 函数【推荐,性能最佳】
AC 代码
-- 解决方案(1)
SELECT DISTINCT w1.id
FROM Weather w1, Weather w2
WHERE DATEDIFF(w1.recordDate, w2.recordDate) = 1 AND w1.Temperature > w2.Temperature
-- 解决方案(2)
SELECT a.id
FROM Weather AS a CROSS JOIN Weather AS b
ON TIMESTAMPDIFF(DAY, a.recordDate, b.recordDate) = -1
WHERE a.Temperature > b.Temperature;
-- 解决方案(3)
SELECT a.id
FROM Weather a JOIN Weather b
ON (a.recorddate = ADDDATE(b.recorddate, INTERVAL 1 DAY))
WHERE a.temperature > b.temperature