C
C
cats_wrath2021-09-21 03:06:52
SQL
cats_wrath, 2021-09-21 03:06:52

Show fullness of classes, what's wrong?

There are two tables:
Student_in_class has fields:
--id - record number
--class - class identifier
--student - student
Class has fields: --id
- class identifier --name
- class name select the resulting table: name, count I wrote a query that seems to show the correct data, but this solution is incorrect: SELECT name, (SELECT COUNT(Class.name=Student_in_class.class) FROM Student_in_class WHERE (Class.id = Student_in_class. class)) AS count FROM Class ORDER BY count DESC Tell me what to fix




Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
N, 2021-09-21
@Fernus

SELECT `name`, COUNT(`Student_in_class`.*) AS `count`
LEFT JOIN `Student_in_class` ON `Student_in_class`.`class` = `Class`.`id`
FROM `Class`
GROUP BY `Class`.`id`
ORDER BY `count` DESC

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question