Skip to content

1126. Active Businesses 👍

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
WITH
  AvgEvents AS (
    SELECT
      business_id,
      AVG(occurrences) OVER(PARTITION BY event_type) AS event_avg_occurrences,
      occurrences
    FROM Events
  )
SELECT business_id
FROM AvgEvents
GROUP BY 1
HAVING SUM(IF(occurrences > event_avg_occurrences, 1, 0)) > 1;