SELECT concat(date(alltable.t_stamp), ' ', hour(alltable.t_stamp), ':00') as StartTimestamp,
	concat('H',TIMESTAMPDIFF(HOUR,DATE_FORMAT(alltable.t_stamp,"%Y-%m-%d %H:00:00"),DATE_FORMAT(now(),"%Y-%m-%d %H:00:00"))) as Hour,
	COUNT(*) AS Total,
	SUM(SUBSTRING(alltable.ScanLabel,1,1) <> '?' AND 
	SUBSTRING(alltable.ScanLabel,1,1) <> '9' AND 
	SUBSTRING(alltable.ScanLabel,1,1) <> '0') AS GoodRead,
	SUM(SUBSTRING(alltable.ScanLabel,1,1) = '?') AS NoRead,
	SUM(SUBSTRING(alltable.ScanLabel,1,1) = '9') AS MultiRead,
	SUM(SUBSTRING(alltable.ScanLabel,1,1) = '0') AS NoCode
FROM alltable
Where (alltable.t_stamp BETWEEN :starttime AND :endtime)
GROUP BY hour(alltable.t_stamp)