SELECT NOW()                          AS time, 1 AS name, CAST(COALESCE(SUM(ulc1 = 1), 0) AS SIGNED) AS count
FROM dumper_cycles
WHERE t_stamp BETWEEN :starttime AND :endtime
UNION ALL
SELECT NOW() + INTERVAL 1 SECOND      , 2      , CAST(COALESCE(SUM(ulc2 = 1), 0) AS SIGNED)
FROM dumper_cycles
WHERE t_stamp BETWEEN :starttime AND :endtime
UNION ALL
SELECT NOW() + INTERVAL 2 SECOND      , 3      , CAST(COALESCE(SUM(ulc3 = 1), 0) AS SIGNED)
FROM dumper_cycles
WHERE t_stamp BETWEEN :starttime AND :endtime
UNION ALL
SELECT NOW() + INTERVAL 3 SECOND      , 4      , CAST(COALESCE(SUM(ulc4 = 1), 0) AS SIGNED)
FROM dumper_cycles
WHERE t_stamp BETWEEN :starttime AND :endtime
ORDER BY name;
