WITH LANES AS (
	SELECT
		DATE_FORMAT(MIN(timestamp), "%Y-%m-%d %H:00") AS start_timestamp,
		CONCAT("H",
			CAST(
				TIMESTAMPDIFF(
					HOUR,
					DATE_FORMAT(MIN(timestamp), "%Y-%m-%d %H:00:00"),
					DATE_FORMAT(LEAST(CURRENT_TIMESTAMP(), :endDate), "%Y-%m-%d %H:00:00")
				) AS CHAR
			)
		) AS hour,
		SUM(count) AS total
	FROM pe_history
	WHERE timestamp BETWEEN :startDate AND :endDate
      AND lane_id=:lane
	GROUP BY DATE_FORMAT(timestamp, "%Y-%m-%d %H:00")
)
SELECT
	start_timestamp,
    hour,
	/* Counts: */
	total AS total_count,
	/* PPH: */
	total AS total_pph,
	/* Percents: */
	ROUND(total/total, 4) AS total_percent
FROM LANES;