2022-12-09:上升的温度。以下的数据输出2和4,2015-01-02 的温度比前一天高(10 -> 25),2015-01-04 的温度比前一天高(20 -> 30),sql语句如何写? DR

2023-07-10,,

2022-12-09:上升的温度。以下的数据输出2和4,2015-01-02 的温度比前天高(10 -> 25),2015-01-04 的温度比前一天高(20 -> 30),sql语句如何写?

DROP TABLE IF EXISTS `weather`;
CREATE TABLE `weather` (
`id` int(11) NOT NULL,
`record_date` date DEFAULT NULL,
`temperature` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1; INSERT INTO `weather` VALUES ('1', '2015-01-01', '10');
INSERT INTO `weather` VALUES ('2', '2015-01-02', '25');
INSERT INTO `weather` VALUES ('3', '2015-01-03', '20');
INSERT INTO `weather` VALUES ('4', '2015-01-04', '30');

答案2022-12-09:

sql语句如下:

select a.id, a.record_date
from weather as a cross join weather as b
on datediff(a.record_date, b.record_date) = 1
where a.temperature > b.temperature;

执行结果如下:

2022-12-09:上升的温度。以下的数据输出2和4,2015-01-02 的温度比前一天高(10 -> 25),2015-01-04 的温度比前一天高(20 -> 30),sql语句如何写? DR的相关教程结束。

《2022-12-09:上升的温度。以下的数据输出2和4,2015-01-02 的温度比前一天高(10 -> 25),2015-01-04 的温度比前一天高(20 -> 30),sql语句如何写? DR.doc》

下载本文的Word格式文档,以方便收藏与打印。