Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Leetcode | 上升的温度 #14

Open
techiall opened this issue Jun 30, 2018 · 0 comments
Open

Leetcode | 上升的温度 #14

techiall opened this issue Jun 30, 2018 · 0 comments

Comments

@techiall
Copy link
Owner

给定一个 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 |
+----+

mysql

题目不是很难,就是有一个函数需要了解一下,TO_DAYS 给定一个日期 date,返回一个天数(年份从0开始的天数)。第一次直接拿两个值进行比较,挂了一次。和日期有关的值,记得使用 TO_DAYS。

select b.Id from
Weather a inner join Weather b
on TO_DAYS(a.RecordDate) = TO_DAYS(b.RecordDate) - 1
where b.Temperature > a.Temperature
@techiall techiall assigned techiall and unassigned techiall Aug 6, 2018
@techiall techiall changed the title 上升的温度 Leetcode | 上升的温度 Oct 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant