首页 > 数据库技术 > 详细

大数据第39天—Mysql练习题10-上升的温度-杨大伟

时间:2020-08-16 16:23:13      阅读:83      评论:0      收藏:0      [点我收藏+]

需求:编写一个 SQL 查询,来查找与之前(昨天的)日期相比温度更高的所有日期的 Id。

1 Create table If Not Exists Weather (Id int, RecordDate date, Temperature int);
2 
3 insert into Weather (Id, RecordDate, Temperature) values (1, 2015-01-01, 10);
4 insert into Weather (Id, RecordDate, Temperature) values (2, 2015-01-02, 25);
5 insert into Weather (Id, RecordDate, Temperature) values (3, 2015-01-03, 20);
6 insert into Weather (Id, RecordDate, Temperature) values (4, 2015-01-04, 30);

最终SQL:

1 SELECT
2     weather.id AS Id
3 FROM
4     weather
5 JOIN
6     weather w 
7 ON 
8     DATEDIFF(weather.RecordDate, w.RecordDate) = 1
9 AND weather.Temperature > w.Temperature;

 

大数据第39天—Mysql练习题10-上升的温度-杨大伟

原文:https://www.cnblogs.com/shui68home/p/13512579.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!