BNA8/.resources/9952d77a07e11a8ca5852860fcdf5088f5f40c9ac5d226d0249259ad03906c8c

103 lines
4.0 KiB
Plaintext

WITH SORTERS AS (
SELECT
MIN(s04_timestamp) AS start_timestamp,
MAX(s04_timestamp) AS end_timestamp,
3600/TIMESTAMPDIFF(SECOND, :startDate, :endDate) AS pph_multiplier,
sorter,
COUNT(*) AS total,
SUM(sort_code="Success") AS success,
SUM(sort_code="Unknown") AS unknown,
SUM(sort_code="Unexpected") AS unexpected,
SUM(sort_code="Track Err") AS track_err,
SUM(sort_code="Gap Err") AS gap_err,
SUM(sort_code="Dest Full") AS dest_full,
SUM(sort_code="Dest Fault") AS dest_fault,
SUM(sort_code="Dest Invalid") AS dest_invalid,
SUM(sort_code="No Read") AS no_read,
SUM(sort_code="No Code") AS no_code,
SUM(sort_code="Multi Label") AS multi_label,
SUM(sort_code="Dest Disabled") AS dest_disabled,
SUM(sort_code="Rate High") AS rate_high,
SUM(sort_code="Div Fail") AS div_fail,
SUM(sort_code="Dest None") AS dest_none,
SUM(sort_code="Lost") AS lost,
SUM(sort_code="Dim Err") AS dim_err,
SUM(sort_code="Weight Err") AS weight_err,
SUM(sort_code="Underutilized") AS underutilized,
SUM(sort_code="Unsafe") AS unsafe
FROM package_history
WHERE s04_timestamp BETWEEN :startDate AND :endDate
GROUP BY sorter
ORDER BY sorter
)
SELECT
start_timestamp,
end_timestamp,
sorter,
/* Counts: */
total AS total_count,
success AS success_count,
unknown AS unknown_count,
unexpected AS unexpected_count,
track_err AS track_err_count,
gap_err AS gap_err_count,
dest_full AS dest_full_count,
dest_fault AS dest_fault_count,
dest_invalid AS dest_invalid_count,
no_read AS no_read_count,
no_code AS no_code_count,
multi_label AS multi_label_count,
dest_disabled AS dest_disabled_count,
rate_high AS rate_high_count,
div_fail AS div_fail_count,
dest_none AS dest_none_count,
lost AS lost_count,
dim_err AS dim_err_count,
weight_err AS weight_err_count,
underutilized AS underutilized_count,
unsafe AS unsafe_count,
/* PPH: */
ROUND(total*pph_multiplier) AS total_pph,
ROUND(success*pph_multiplier) AS success_pph,
ROUND(unknown*pph_multiplier) AS unknown_pph,
ROUND(unexpected*pph_multiplier) AS unexpected_pph,
ROUND(track_err*pph_multiplier) AS track_err_pph,
ROUND(gap_err*pph_multiplier) AS gap_err_pph,
ROUND(dest_full*pph_multiplier) AS dest_full_pph,
ROUND(dest_fault*pph_multiplier) AS dest_fault_pph,
ROUND(dest_invalid*pph_multiplier) AS dest_invalid_pph,
ROUND(no_read*pph_multiplier) AS no_read_pph,
ROUND(no_code*pph_multiplier) AS no_code_pph,
ROUND(multi_label*pph_multiplier) AS multi_label_pph,
ROUND(dest_disabled*pph_multiplier) AS dest_disabled_pph,
ROUND(rate_high*pph_multiplier) AS rate_high_pph,
ROUND(div_fail*pph_multiplier) AS div_fail_pph,
ROUND(dest_none*pph_multiplier) AS dest_none_pph,
ROUND(lost*pph_multiplier) AS lost_pph,
ROUND(dim_err*pph_multiplier) AS dim_err_pph,
ROUND(weight_err*pph_multiplier) AS weight_err_pph,
ROUND(underutilized*pph_multiplier) AS underutilized_pph,
ROUND(unsafe*pph_multiplier) AS unsafe_pph,
/* Percents: */
ROUND(total/total, 4) AS total_percent,
ROUND(success/total, 4) AS success_percent,
ROUND(unknown/total, 4) AS unknown_percent,
ROUND(unexpected/total, 4) AS unexpected_percent,
ROUND(track_err/total, 4) AS track_err_percent,
ROUND(gap_err/total, 4) AS gap_err_percent,
ROUND(dest_full/total, 4) AS dest_full_percent,
ROUND(dest_fault/total, 4) AS dest_fault_percent,
ROUND(dest_invalid/total, 4) AS dest_invalid_percent,
ROUND(no_read/total, 4) AS no_read_percent,
ROUND(no_code/total, 4) AS no_code_percent,
ROUND(multi_label/total, 4) AS multi_label_percent,
ROUND(dest_disabled/total, 4) AS dest_disabled_percent,
ROUND(rate_high/total, 4) AS rate_high_percent,
ROUND(div_fail/total, 4) AS div_fail_percent,
ROUND(dest_none/total, 4) AS dest_none_percent,
ROUND(lost/total, 4) AS lost_percent,
ROUND(dim_err/total, 4) AS dim_err_percent,
ROUND(weight_err/total, 4) AS weight_err_percent,
ROUND(underutilized/total, 4) AS underutilized_percent,
ROUND(unsafe/total, 4) AS unsafe_percent
FROM SORTERS;