Junior — Middle
How to select from the table those records where the number of students exceeds twenty?
sobes.tech AI
Answer from AI
To select records from a table where the number of students exceeds 20, an SQL query with a condition in WHERE or HAVING is used, depending on the data structure.
If the table has a field students_count, the query will be simple:
SELECT * FROM table_name WHERE students_count > 20;
If the number of students needs to be calculated from a related table (for example, there is a groups table and a students table, where students have a group_id), then an aggregate function COUNT with grouping is used:
SELECT group_id, COUNT(*) AS students_count
FROM students
GROUP BY group_id
HAVING COUNT(*) > 20;
This query will return groups with more than 20 students.