Untitled
Anonymous
plain_text
02/08/2024 4:34 PM
656 B
17
Indexable
SELECT
e.EmployeeID,
e.PostalCode,
AVG(num_customers) AS avg_customer_count
FROM (
SELECT
t.EmployeeID,
COUNT(DISTINCT t.customer_id) AS num_customers
FROM
`project_id.dataset_name.transactions` t
INNER JOIN
`project_id.dataset_name.employees` e ON t.EmployeeID = e.EmployeeID
WHERE
e.PostalCode IS NOT NULL
GROUP BY
t.EmployeeID,
e.PostalCode
) AS EmployeeCustomerCounts
GROUP BY
e.EmployeeID,
e.PostalCode;
Editor is loading...
Leave a Comment