diff --git a/src/sql/0-run-first/1-sanitize_init.sql b/src/sql/0-run-first/1-sanitize_init.sql index 05724b3..194bfe3 100644 --- a/src/sql/0-run-first/1-sanitize_init.sql +++ b/src/sql/0-run-first/1-sanitize_init.sql @@ -33,3 +33,17 @@ ALTER TABLE project_lifecycle CREATE OR REPLACE INDEX lifecycle_timestamp on project_lifecycle (timestamp); CREATE OR REPLACE INDEX lifecycle_newval on project_lifecycle (new_value); + +######### technician categories ############## + +CREATE OR REPLACE TABLE technician_category AS +SELECT DISTINCT users.email, + CONCAT(SUBSTR(ap.refnum, 1, 3), ' - ', + IF(ap.proj_type = 'Warranty', 'Structural', ap.proj_type)) AS flavor, + count(email) AS count +FROM users + INNER JOIN dispatch d ON users.pkey = d.dispatched_to + INNER JOIN all_projects ap ON d.project_fkey = ap.refnum +#where date_dispatched between NOW() - INTERVAL 180 DAY AND NOW() +GROUP BY flavor, email +ORDER BY count DESC;