Попробуйте свести с группировкой
SELECT client,
flag,
start_hour,
Group_concat(IF(deploy_time='8', count, NULL)) AS '8h',
Group_concat(IF(deploy_time='9', count, NULL)) AS '9h',
Group_concat(IF(deploy_time='10', count, NULL)) AS '10h',
Group_concat(IF(deploy_time='11', count, NULL)) AS '11h',
Group_concat(IF(deploy_time='16', count, NULL)) AS '16h',
Group_concat(IF(deploy_time='17', count, NULL)) AS '17h'
FROM (SELECT client,
Sum(count) count,
start_hour,
flag,
IF(deploy_time = 0, start_hour, deploy_time) deploy_time
FROM sample
GROUP BY 1,
3,
4,
5) tb1
GROUP BY client,
flag,
start_hour
WITH ROLLUP
HAVING grouping(client) = 1 and grouping(flag) = 1 and grouping(Starg_hour) =1
ORDER BY 1,
3;
Справочник по группировке