SQLize Online / PHPize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
create table autoposting_planned ( id int auto_increment, postdate datetime, primary key (id) ); insert into autoposting_planned(postdate) values ('2022-07-13 02:00:00'), ('2022-07-11 05:00:00'), ('2022-07-11 07:00:00'), ('2022-07-11 08:00:00'), ('2022-07-12 05:00:00'), ('2022-07-12 07:00:00'), ('2022-07-12 08:00:00'), ('2022-07-13 05:00:00'), ('2022-07-13 07:00:00'), ('2022-07-13 08:00:00'), ('2022-07-14 02:00:00'), ('2022-07-14 05:00:00'), ('2022-07-14 07:00:00'); select date_format(postdate, '%Y-%m-%d') as date, group_concat(date_format(postdate, '%H:%i')), count(distinct FIELD(date_format(postdate, '%H:%i'), '02:00', '05:00', '07:00', '08:00')) as count from autoposting_planned where postdate > now() group by date_format(postdate, '%Y-%m-%d') having count < 4 order by date limit 1; select ifnull( (select date_format(postdate, '%Y-%m-%d') as date from autoposting_planned where postdate > now() group by date_format(postdate, '%Y-%m-%d') having count(distinct find_in_set(date_format(postdate, '%H:%i'), '02:00,05:00,07:00,08:00')) < 4 order by date limit 1), (select max(DATE_ADD(postdate, INTERVAL 1 DAY)) from autoposting_planned) );
Stuck with a problem? Got Error? Ask ChatGPT!
Copy Clear