DateBase -- Rising Temperature

Question:

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

Analysis:

给出一张温度表格,写一个SQL语句找出所有的温度比前一天温度高的日期id。

数据库的题目,常年不用都忘了。跑去官网查文档,一点点拾起来吧~

Answer:

select w1.id from Weather w1, Weather w2 where w1.Temperature > w2.Temperature and DATEDIFF(w1.Date, w2.Date) = 1;
时间: 2024-10-24 11:11:52

DateBase -- Rising Temperature的相关文章

LeetCode:Rising Temperature - 上浮的温度

1.题目名称 Rising Temperature(上浮的温度) 2.题目地址 https://leetcode.com/problems/rising-temperature 3.题目内容 给出一组每日的气温数据,返回当日气温高于昨日气温的日期. 例如,Weather表中的数据如下: +---------+------------+------------------+ | Id(INT) | Date(DATE) | Temperature(INT) | +---------+-------

[LeetCode][SQL]Rising Temperature

https://leetcode.com/problems/rising-temperature/ Rising Temperature Given a Weather table, write a SQL query to find all dates' Ids with higher temperature compared to its previous (yesterday's) dates. +---------+------------+------------------+ | I

Rising Temperature

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

LeetCode - Rising Temperature

Description:Given a Weather table, write a SQL query to find all dates' Ids with higher temperature compared to its previous (yesterday's) dates. 选出比前一天温度高的Id 使用自连接,to_days函数是返回从零年开始的总天数. (为何把=误写成<会Runtime Error啊 不应该是WrongAnser!) # Write your MySQL q

[SQL]197. Rising Temperature

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

leetcode:Rising Temperature

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

Leetcode 197. Rising Temperature

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

Rising Temperature [MySQL]

题目: 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) | +---------+------------+

leetcode数据库sql之Rising Temperature

leetcode原文引用: 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) | +---------+---