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,

    CONCAT(CAST(SUM(dc.ulc1 = 1) AS CHAR),' cph') AS ULC1,
    CONCAT(CAST(SUM(dc.ulc2 = 1) AS CHAR),' cph') AS ULC2,
    CONCAT(CAST(SUM(dc.ulc3 = 1) AS CHAR),' cph') AS ULC3,
    CONCAT(CAST(SUM(dc.ulc4 = 1) AS CHAR),' cph') AS ULC4,
    CONCAT(CAST(SUM(dc.ulc5 = 1) AS CHAR),' cph') AS ULC5,
    CONCAT(CAST(SUM(dc.ulc6 = 1) AS CHAR),' cph') AS ULC6,
    CONCAT(CAST(SUM(dc.ulc7 = 1) AS CHAR),' cph') AS ULC7,
    CONCAT(CAST(SUM(dc.ulc8 = 1) AS CHAR),' cph') AS ULC8

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