SELECT `t`.`from` AS `interval`, COUNT(*) AS `count`
FROM (
SELECT CAST('00:00' AS TIME) AS `from`, CAST('01:00' AS TIME) AS `to`
UNION ALL SELECT CAST('01:00' AS TIME), CAST('02:00' AS TIME)
...
UNION ALL SELECT CAST('23:00' AS TIME), CAST('24:00' AS TIME)
) AS `t`
LEFT JOIN `visitor_stat` AS `v`
ON `v`.`time` >= `t`.`from` AND `v`.`time` < `t`.`to`
WHERE `date` >= :sTime AND `date <= :eTime
GROUP BY `t`.`from`
ORDER BY `t`.`from`
!includedir /etc/my.cnf.d
class ResponseObject
{
private const CLASSES = [
'type1' => 'ResponseObject1',
'type2' => 'ResponseObject2',
'type3' => 'ResponseObject3',
'type4' => 'ResponseObject4'
];
public static function parse(object $data): mixed
{
if (array_key_exists($data->type, static::CLASSES)) {
$class = static::CLASSES[$data->type];
return new $class($data);
}
}
}