WITH LANES AS (
	SELECT
		MIN(timestamp) AS start_timestamp,
		MAX(timestamp) AS end_timestamp,
        3600/TIMESTAMPDIFF(SECOND, :startDate, :endDate) AS pph_multiplier,
		lane_id AS chute,
		SUM(count) AS total
	FROM pe_history
	WHERE timestamp BETWEEN :startDate AND :endDate
	  AND lane_id LIKE "RS%4CH"
	GROUP BY lane_id
    ORDER BY lane_id
)
SELECT
	start_timestamp,
	end_timestamp,
    chute,
    /*CASE chute
    	WHEN "RE5-1CH" THEN "RB49/40"
    	WHEN "RE5-2CH" THEN "RB47/48"
    	WHEN "RE5-3CH" THEN "RB45/46"
    	WHEN "RE5-4CH" THEN "RB43/44"
    	WHEN "RE5-5CH" THEN "RB41/42"
    	WHEN "RE5-6CH" THEN "RB22/21"
    	WHEN "RE5-7CH" THEN "RB24/23"
    	WHEN "RE5-8CH" THEN "RB26/25"
    	WHEN "RE5-9CH" THEN "RB28/27"
    	WHEN "RE5-10CH" THEN "RB20/29"
    	ELSE "Unknown"
    END AS robins,*/
	/* Counts: */
	total AS total_count,
	/* PPH: */
	ROUND(total*pph_multiplier) AS total_pph,
	/* Percents: */
	ROUND(total/total, 4) AS total_percent
FROM LANES;