views:

481

answers:

1

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
+3  A: 

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
MikeW
You are right about distinct and group by before order by.
Bryan