Group and Count by Category
Given a list of students with their course, write a query using GROUP BY to count how many students are enrolled in each course.
Approach: insert every student into a table, then SELECT course, COUNT(*) FROM students GROUP BY course, ordered by course name for a predictable result.
Input: First line: the number of students n. Next n lines: name,course.
Output: One line per course: a tuple (course, count), ordered alphabetically by course.
5 Aditi,CS Rohan,AI Zara,CS Karan,AI Meera,CS
('AI', 2)
('CS', 3)- 1 <= n <= 1000
Hint 1
SELECT course, COUNT(*) FROM students GROUP BY course counts how many rows share each course value.
Hint 2
Add ORDER BY course so the result order is always the same, regardless of insertion order.
GROUP BY course collapses all rows sharing the same course value into one group per course, and COUNT(*) counts how many rows fell into each group. Adding ORDER BY course guarantees a consistent, alphabetical output order regardless of the order students were inserted in.