SELECT
	sorter,
    scanner,
    COUNT(*) AS count,
    ROUND(COUNT(*)*3600/TIMESTAMPDIFF(SECOND, :startDate, :endDate)) AS rate,
    ROUND(AVG(gap_leading/10), 1) AS avg_gap_leading,
    ROUND(AVG(gap_trailing/10), 1) AS avg_gap_trailing,
    ROUND(AVG(pkg_length/10), 1) AS avg_pkg_length
FROM package_history
WHERE s04_timestamp BETWEEN :startDate AND :endDate
GROUP BY sorter, scanner;