Easy and Simple Solution | Beginner-friendly🚀
CodeIf you found this solution helpful, please give it an upvote! 🌟✨ It really motivates me to share more solutions like this. 😊👍
Happy coding! 💻🐱‍🏍
IntuitionWe
# Code
```mysql []
# Write your MySQL query statement below
select class
from Courses
group by class
having count(class)>=5
```
**If you found this solution helpful, please give it an upvote! 🌟✨ It really motivates me to share more solutions like this. 😊👍
Happy coding! 💻🐱‍🏍**
<img src="https://assets.leetcode.com/users/images/6e8c623a-1111-4d21-9a5b-54e00e7feabb_1738093236.165277.jpeg" width=250px>
# Intuition
We need to find the classes that have at least **5 students enrolled**. The `Courses` table contains records of students and their respective classes. Our goal is to count the number of students in each class and return only those classes where the count is **greater than or equal to 5**.

# Approach
1. **Group by `class`**  
   - This ensures we count students separately for each class.

2. **Count students in each class**  
   - Use `COUNT(class)` to determine the number of students in each class.

3. **Filter classes with at least 5 students**  
   - Use `HAVING COUNT(class) >= 5` to include only those classes that meet the requirement.

# Complexity Analysis
- **Grouping (`GROUP BY class`)**  
  - This operation sorts and groups the records, leading to **O(N log C)** complexity, where `C` is the number of unique classes.

- **Counting (`COUNT(class)`)**  
  - Runs in **O(N)** since we count the occurrences in each group.

- **Filtering with `HAVING`**  
  - This operation is **O(C)**, where `C` is the number of unique classes.

### **Overall Complexity:**
- The dominant factor is **grouping and counting**, leading to an approximate **O(N log C) ≈ O(N log N)** complexity in the worst case.
['MySQL']