58 - 上升的温度
Last updated
Was this helpful?
Last updated
Was this helpful?
给定一个 Weather 表,编写一个 SQL 查询,来查找与之前(昨天的)日期相比温度更高的所有日期的 Id。
+---------+------------------+------------------+ | Id(INT) | RecordDate(DATE) | Temperature(INT) | +---------+------------------+------------------+ | 1 | 2015-01-01 | 10 | | 2 | 2015-01-02 | 25 | | 3 | 2015-01-03 | 20 | | 4 | 2015-01-04 | 30 | +---------+------------------+------------------+
例如,根据上述给定的 Weather 表格,返回如下 Id:
+----+ | Id | +----+ | 2 | | 4 | +----+
比较日期的函数:datediff()
,可以算出两个日期相差的天数
作者:LeetCode
链接:
Runtime: 398 ms, faster than 41.07% of MySQL online submissions forRising Temperature.
Memory Usage: N/A
如果join可以的话,那么where可以不?
Runtime: 886 ms, faster than 6.73% of MySQL online submissions forRising Temperature.
Memory Usage: N/A
可以是可以,但不知道为啥要慢那么多
又看到一种解法:
Runtime: 337 ms, faster than 66.03% of MySQL online submissions forRising Temperature.
Memory Usage: N/A
不知道为啥能快那么多,仅仅是把join
换成了cross join
In MySQL, JOIN, CROSS JOIN, and INNER JOIN are syntactic equivalents (they can replace each other). In standard SQL, they are not equivalent. INNER JOIN is used with an ON clause, CROSS JOIN is used otherwise.
但cross join不能用on
来筛选,甚至就不能判断。能加都是mysql
加上去的。
作者:rotcod-wang 链接:
但是在提到,官方文件说join, cross join, inner join都一样。就是排列组合一下两个表。