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
1 个解决方案
#1
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.
很确定你也需要在order by子句之前使用group by子句。
select state, avg(lat), avg(lon)
from tRealtyTrac
group by state
order by state
#1
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.
很确定你也需要在order by子句之前使用group by子句。
select state, avg(lat), avg(lon)
from tRealtyTrac
group by state
order by state