gpt4 book ai didi

MySQL 查找获得最高正进展需要多少天

转载 作者:行者123 更新时间:2023-11-29 17:53:21 25 4
gpt4 key购买 nike

数据集:

CREATE TABLE TEMPERATURES (
CREATED DATE,
ACTUAL_TEMPERATURE FLOAT
);

INSERT INTO TEMPERATURES VALUES
('20170101',12.2),
('20170103',10.1),
('20170112',14.2),
('20170115',12.5),
('20170205',20.8),
('20170122',16.7),
('20170123',7.8),
('20170130',12.5),
('20170201',13.7),
('20170302',14.8),
('20170313',11.1),
('20170414',12.0),
('20170525',10.4);

和 SQL FIDDLE 相同:http://sqlfiddle.com/#!9/9b11e

我只是想知道需要多少天才能获得最高的正进展?

我想要的结果是:

20170103 10.1
20170205 20.8

小心点,我不想:

20170123 7.8
20170302 14.8

我尝试了很多请求和很多方法,但没有成功。

是否可能,如果可以,如何实现?

感谢您的帮助。

最佳答案

根据您对问题的描述,我认为您想要:

select grp, min(created), max(created),
min(actual_temperature), max(actual_temperature)
from (select t.*,
(@grp := @grp + coalesce(prev_at > actual_temperature, 0)) as grp
from (select t.*,
(select t2.actual_temperature
from temperatures t2
where t2.created < t.created
order by t2.created desc
limit 1
) as prev_at
from temperatures t
order by created
) t cross join
(select @grp := 0) params
) t
group by grp
order by max(actual_temperature) - min(actual_temperature) desc
limit 1;

这可以识别温度升高的条纹。然后它返回最大值和最小值之间差异最大的条纹。

这就是我解释你的问题的方式,尽管你的结果并不完全符合这种解释。

关于MySQL 查找获得最高正进展需要多少天,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49109368/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com