1

だから私はクエリを持っています:

select states, count(numberofcounty) 
from countytable 
group by states  
order by count(distinct numberofcounty) ASC;

これは、州の数と郡の数の 2 列のテーブルを返します。単一の実数で州ごとにいくつの郡があるかの平均を取得するにはどうすればよいですか?

テーブル構造は次のとおりです。

create table numberofcounty(
    numberofcounty text, 
    states text references states(states), 
);
create table states (
    states text primary key,  
    name text, 
    admitted_to_union text

);

4

3 に答える 3

2

これかも?

countytable:
state|county
a     aa
a     ab
a     ac
b     ba


SELECT AVG(counties) FROM (SELECT state, COUNT(county) as counties FROM countytable GROUP BY state) as temp

結果: 2

于 2013-10-13T23:05:20.913 に答える