Coding Test

Leetcode -1126. Active Businesses

Indo Yoon


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.


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

SELECT business_id
    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