gpt4 book ai didi

MySQL为每个id选择最低的时间日期

转载 作者:行者123 更新时间:2023-11-30 00:25:51 25 4
gpt4 key购买 nike

我有这张表:

CREATE TABLE IF NOT EXISTS `event_showtime` (
`id_show` int(11) NOT NULL AUTO_INCREMENT,
`id_event` int(11) NOT NULL,
`latitude` double NOT NULL,
`longitude` double NOT NULL,
`event_date_time` datetime NOT NULL,
PRIMARY KEY (`id_show`),
KEY `id_event` (`id_event`)
)

值看起来像这样,例如:

INSERT INTO `event_showtime` (`id_show`, `id_event`, `latitude`, `longitude`, `event_date_time`) VALUES
(1, 1, 49.2016762922894, 18.7615620750428, '2014-03-31 16:13:17'),
(2, 1, 49.2016762922894, 18.7615620750428, '2014-04-01 20:00:00'),
(3, 2, 49.2113914818564, 18.7520992416382, '2014-03-31 15:00:00'),
(4, 2, 49.0545135142313, 20.2952223676682, '2014-04-16 11:00:00'),
(5, 2, 49.2113914818564, 18.7520992416382, '2014-04-23 11:00:00'),
(6, 2, 49.0545135142313, 20.2952223676682, '2014-04-30 11:00:00'),
(7, 2, 49.2016762922894, 18.7615620750428, '2014-04-29 12:00:00'),
(8, 1, 49.2016762922894, 18.7615620750428, '2014-04-24 12:00:00');

我想以这种方式选择结果:

对于每个 id_event,我想选择最近的日期,即 > NOW(),因此结果应如下所示:

`id_event` `event_date_time` 
1 , '2014-04-24 12:00:00'
2 , '2014-04-16 11:00:00'

如何实现这一目标? :)

最佳答案

select id_event, min(event_date_time) as lowest_date
from event_showtime
where event_date_time > now()
group by id_event

关于MySQL为每个id选择最低的时间日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22893535/

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