SELECT
    CONCAT(DATE(dc.t_stamp), ' ', HOUR(dc.t_stamp), ':00') AS StartTimestamp,
    CONCAT('H', TIMESTAMPDIFF(HOUR,
        DATE_FORMAT(dc.t_stamp, "%Y-%m-%d %H:00:00"),
        DATE_FORMAT(NOW(), "%Y-%m-%d %H:00:00"))) AS Hour,

    SUM(dc.ulgl1 = 1) AS ULGL1,
    SUM(dc.ulgl2 = 1) AS ULGL2,
    SUM(dc.ulgl3 = 1) AS ULGL3,
    SUM(dc.ulgl4 = 1) AS ULGL4,
    SUM(dc.ulgl5 = 1) AS ULGL5,
    SUM(dc.ulgl6 = 1) AS ULGL6,
    SUM(dc.ulgl7 = 1) AS ULGL7,
    SUM(dc.ulgl8 = 1) AS ULGL8

FROM dumper_cycles dc
WHERE dc.t_stamp BETWEEN :starttime AND :endtime
GROUP BY HOUR(dc.t_stamp);
