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_count,
	SUM(alltable.ACTUAL_DEST <> 'S03999') AS Diverted,
	SUM(alltable.DivertStatus = 14) AS DivertFail,
	SUM(alltable.DivertStatus = 5) AS DestinationFull,
	SUM(alltable.DivertStatus = 6) AS DestinationJam,
	SUM(alltable.DivertStatus = 12) AS DestinationDisabled,
	SUM(alltable.DivertStatus = 6) as DestinationFault,
	SUM(alltable.DivertStatus = 17) as Lost,
	SUM(alltable.DivertStatus = 21) as Unsafe,
	SUM(alltable.DivertStatus = 18) as DimError,
	SUM(alltable.DivertStatus = 4) as GapError,
	SUM(alltable.DivertStatus = 1) as Unknown	
FROM alltable
Where (alltable.DEST_REQ = :lane AND alltable.t_stamp BETWEEN :starttime AND :endtime)
GROUP BY hour(alltable.t_stamp)