Grouping and sorting - column must appear in the GROUP BY issues

The error is basically saying that every column in your select clause must also be either:

  1. An aggregate or
  2. Also included in the group by.

The reason is this: you are grouping values. if you have:

select bus_id, route_name group by bus_id

then somehow the database has to work out what to do with the route_name column. Return the first one? Last one? Average? you get the picture…

So you might (as an example only, not at all suggesting valid in your case):

select bus_id, min(route_name) group by bus_id