3 Solutions in MySQL | GROUP BY, Window function & Correlated Subquery
1. GROUP BY & HAVING clause with Runtime 306 ms that (beats 63.93%)\n- Time complexity: O(n)\n\n- Space complexity: O(k)\n\n# Code\nmysql []\nSELECT \n    class
# 1. GROUP BY & HAVING clause with Runtime 306 ms that (beats 63.93%)\n- Time complexity: O(n)\n\n- Space complexity: O(k)\n\n# Code\n```mysql []\nSELECT \n    class\nFROM  Courses\nGROUP BY class\nHAVING COUNT(1) >= 5;\n\n```\n\n# 2. Window function with Runtime 314 ms that (beats 56.77%) \n- Time complexity: O(n)\n\n- Space complexity: O(n)\n\n# Code\n```mysql []\nSELECT \n    DISTINCT class\nFROM (\n    SELECT \n        class, \n        COUNT(1) OVER (PARTITION BY class) AS frequency\n    FROM Courses\n) res\nWHERE res.frequency >= 5;\n\n```\n\n# 3. Correlated Subquery with Runtime 2158 ms that (beats 5.02%)\n- Time complexity: O(n^2)\n\n- Space complexity: O(k)\n\n# Code\n```mysql []\nSELECT \n    DISTINCT c.class\nFROM Courses c\nWHERE 5 <= (\n        SELECT \n            COUNT(1) \n        FROM Courses c1 \n        WHERE  c.class = c1.class \n        GROUP BY c1.class\n    );\n\n```
['MySQL']