BNA8/.resources/f65d62263e73b66ae9a123754cb90aebe008b17ba9dfe40c6e797ff22b0d4efe

25 lines
609 B
Plaintext

WITH LANES AS (
SELECT
MIN(s04_timestamp) AS start_timestamp,
MAX(s04_timestamp) AS end_timestamp,
3600/TIMESTAMPDIFF(SECOND, :startDate, :endDate) AS pph_multiplier,
sorter,
destination_act AS lane,
COUNT(*) AS total
FROM package_history
WHERE s04_timestamp BETWEEN :startDate AND :endDate
GROUP BY sorter, s04_act_dest
ORDER BY sorter, s04_act_dest
)
SELECT
start_timestamp,
end_timestamp,
sorter,
lane,
/* Counts: */
total AS total_count,
/* PPH: */
ROUND(total*pph_multiplier) AS total_pph,
/* Percents: */
ROUND(total/total, 4) AS total_percent
FROM LANES;