SELECT
    CONCAT(DATE(:starttime), ' ', HOUR(:starttime), ':', LPAD(MINUTE(:starttime), 2, '0')) AS StartTimestamp,
    CONCAT(DATE(:endtime), ' ', HOUR(:endtime), ':', LPAD(MINUTE(:endtime), 2, '0')) AS EndTimestamp,
    COALESCE(SUM(dumper_cycles.ulc1 = 1), 0) + COALESCE(SUM(dumper_cycles.ulc2 = 1), 0) + COALESCE(SUM(dumper_cycles.ulc3 = 1), 0) + COALESCE(SUM(dumper_cycles.ulc4 = 1), 0) AS Total,
    COALESCE(SUM(dumper_cycles.ulc1 = 1), 0) AS ULC1,
    COALESCE(SUM(dumper_cycles.ulc2 = 1), 0) AS ULC2,
    COALESCE(SUM(dumper_cycles.ulc3 = 1), 0) AS ULC3,
    COALESCE(SUM(dumper_cycles.ulc4 = 1), 0) AS ULC4
FROM dumper_cycles
WHERE dumper_cycles.t_stamp BETWEEN :starttime AND :endtime

UNION ALL

-- Default row with zeros when no dumper cycles exist
SELECT
    CONCAT(DATE(:starttime), ' ', HOUR(:starttime), ':', LPAD(MINUTE(:starttime), 2, '0')) AS StartTimestamp,
    CONCAT(DATE(:endtime), ' ', HOUR(:endtime), ':', LPAD(MINUTE(:endtime), 2, '0')) AS EndTimestamp,
    0 AS Total,
    0 AS ULC1,
    0 AS ULC2,
    0 AS ULC3,
    0 AS ULC4

WHERE NOT EXISTS (
    SELECT 1 FROM dumper_cycles
    WHERE dumper_cycles.t_stamp BETWEEN :starttime AND :endtime
);