Question

I have a table of locations with latitude, longitude and the U.S. state fields. I would like to select the average latitude and longitude for each state.

I am trying the following code but I get a syntax error on distinct.

select avg(lat), avg(lon), distinct(state) from tRealtyTrac order by state group by state 
Was it helpful?

Solution

You don't need the distinct. If you group by state, you'll get one result for each one anyway

Pretty sure you need the group by clause before the order by clause too.

select state, avg(lat), avg(lon) 
from tRealtyTrac 
group by state 
order by state 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top