pepperwind / answer_key /kpis /csat.sql
rasinmuhammed's picture
Pepperwind Trading Co. preview, version 1.0
27ec678 verified
Raw History Blame Contribute Delete
431 Bytes
-- CSAT (share of ratings 4 or 5)
-- Survey responses scoring 4 or 5, over all responses received in the month.
SELECT strftime(created_at, '%Y-%m') AS month, sum(CASE WHEN score >= 4 THEN 1 ELSE 0 END) AS num, sum(1) AS den, sum(CASE WHEN score >= 4 THEN 1 ELSE 0 END) / NULLIF(sum(1), 0) AS value FROM support.csat_response WHERE created_at >= TIMESTAMP '2023-10-01' AND created_at < TIMESTAMP '2026-10-01' GROUP BY 1 ORDER BY 1