leetcode with MySQL:197. Rising Temperature

题目:

Table: Weather

+---------------+---------+
| Column Name | Type |
+---------------+---------+
| id | int |
| recordDate | date |
| temperature | int |
+---------------+---------+
id is the primary key for this table.
This table contains information about the temperature on a certain day.

Write an SQL query to find all dates' Id with higher temperatures compared to its previous dates (yesterday).

Return the result table in any order.

给定一个table,找出温度比前一天高的日期的id

SELECT a.id AS IdFROM Weather AS a JOIN Weather AS bON a.temperature>b.temperature and DATEDIFF(a.recordDate,b.recordDate)=1;

将该表(a表)跟另一个自己(b表)结合
条件设a表temperature大于b表的temperature且a表recordDate和b表recordDate的差为1
然后把a表的id选出就好
最后执行时间401ms(faster than 87.26%)

那我们下题见


关于作者: 网站小编

码农网专注IT技术教程资源分享平台,学习资源下载网站,58码农网包含计算机技术、网站程序源码下载、编程技术论坛、互联网资源下载等产品服务,提供原创、优质、完整内容的专业码农交流分享平台。

热门文章