Skip to content
Advertisement

Group by issues with multiple columns

I am having trouble making a query work. I am selecting 5 columns, using 3 to filter and 1 to count:

SELECT count(student), class_name, college, date, professor
WHERE *specific condition* = class_name 
AND *specific condition* = college 
AND *specific condition* = date 
GROUP BY professor, college

I keep getting an error that the other columns have to be grouped by or aggregated. I’m trying to get the total students per class per professor. I’m only selecting the other columns so I can filter out data.

Advertisement

Answer

If the other columns are being selected for filtering purposes only, they do not need to be included in the SELECT statement.

The error is being caused because it cannot be decided which of the date and class_name entries the table has to show among the group.

Do try:

SELECT count(student), college, professor
--other lines equal

I don’t see your FROM statement by the way.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement