This Leetcode problem Active Businesses LeetCode Solution is done in SQL.

# List of all LeetCode Solution

## Problem Statement

(business_id, event_type) is the primary key of this table.
Each row in the table logs the info that an event of some type occured at some business for a number of times.

Write an SQL query to find all active businesses. An active business is a business that has more than one event type with occurences greater than the average occurences of that event type among all businesses.

The result format is in the following example.

Example 1:
Input:

Output:

Explanation:
Average for ‘reviews’, ‘ads’ and ‘page views’ are (7+3)/2=5, (11+7+6)/3=8, (3+12)/2=7.5 respectively.
Business with id 1 has 7 ‘reviews’ events (more than 5) and 11 ‘ads’ events (more than 8) so it is an active business.

## Active Businesses LeetCode Solution MySQL

``````select
from
Events e,
(
select
event_type,
avg(occurences) as avg_occurences
from
Events
group by
event_type
) as a
where
e.event_type = a.event_type
and e.occurences > a.avg_occurences
group by