I have a table events which has id and venue columns.
The events.venue column matches the venues.id column, a fairly typical and simple setup.
Some of the venues are 'broken' in that they are missing critical pieces of information, such as geo_lat. I am trying to create a priority list of broken venues, with the venue that is hosting the most events at the top, so that we know which venues are most important to fix.
Myquery so far looks like;
select x.venue_id as id, count(x.venue_id) as events
from (
select *
from events e, venues v
where e.venue=v.id and v.geo_lat is null
group by e.venue
) as x order by events desc
Which is giving the error: ERROR: column "e.id" must appear in the GROUP BY clause or be used in an aggregate function
The output I am trying to achieve would look something like;
venue.id | events
---------|-------
12 | 219
214 | 141
36 | 41
1834 | 22
931 | 4
Containing just the broken venues. That way, I know that fixing venue 12 is top priority and so on.
CREATE TABLEstatements and sample dataINSERTs, along with the expected output you helpfully showed. It makes it much easier to test queries and means folks writing answers don't have to make their own dummy tables and data.