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;

执行结果如下:

在这里插入图片描述