BNA8/.resources/115fd6c3931bbc6fde181333537e97d4b8ca02b9056b2eb775fd6967de31221a
2025-08-13 21:41:10 +04:00

44 lines
1.3 KiB
Plaintext

WITH SCANNERS AS (
SELECT
DATE_FORMAT(MIN(s04_timestamp), "%Y-%m-%d %H:00") AS start_timestamp,
CONCAT("H",
CAST(
TIMESTAMPDIFF(
HOUR,
DATE_FORMAT(MIN(s04_timestamp), "%Y-%m-%d %H:00:00"),
DATE_FORMAT(LEAST(CURRENT_TIMESTAMP(), :endDate), "%Y-%m-%d %H:00:00")
) AS CHAR
)
) AS hour,
COUNT(*) AS total,
SUM(scanner_status NOT IN ("No Read", "No Code", "Multi Label")) AS good_read,
SUM(scanner_status = "No Read") AS no_read,
SUM(scanner_status = "No Code") AS no_code,
SUM(scanner_status = "Multi Label") AS multi_label
FROM package_history
WHERE s04_timestamp BETWEEN :startDate AND :endDate
AND scanner=:scanner
GROUP BY DATE_FORMAT(s04_timestamp, "%Y-%m-%d %H:00")
)
SELECT
start_timestamp,
hour,
/* Counts: */
total AS total_count,
good_read AS good_read_count,
no_read AS no_read_count,
no_code AS no_code_count,
multi_label AS multi_label_count,
/* PPH: */
total AS total_pph,
good_read AS good_read_pph,
no_read AS no_read_pph,
no_code AS no_code_pph,
multi_label AS multi_label_pph,
/* Percents: */
ROUND(total/total, 4) AS total_percent,
ROUND(good_read/total, 4) AS good_read_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
FROM SCANNERS;