Published on

Leetcode -1126. Active Businesses

Authors
  • avatar
    Name
    Indo Yoon
    Twitter
Table of Contents

Problem

[LeetCode - The World’s Leading Online Programming Learning Platform

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

LeetCode

](https://leetcode.com/problems/active-businesses/description/)

Solution

WITH Average AS (
    SELECT event_type, AVG(occurences) as occurences
    FROM Events
    GROUP BY event_type
)

SELECT business_id
FROM (
    SELECT business_id, COUNT(business_id) as counts FROM Events
    JOIN Average ON Events.event_type = Average.event_type
    WHERE Events.occurences > Average.occurences
    GROUP BY business_id
) AS Temp
WHERE counts > 1