我有一张很大的桌子,上面有一些有关国家的信息,包括:
City Name | Province | Country | ...
Honolulu HI US
Hilo HI US
Kihei HI US
Annapolis MD US
Laurel MD US
Sidney LD AU
Camberra PP AU
Darwin PP AU
...
我希望查询看起来像这样(最好使用OVER函数以节省性能):
Country | Count_C | Province | Count_P
US 5 MD 2
US 5 HI 3
AU 3 LD 1
AU 3 PP 2
...
我已经设法做到这一点,但是在使用某些子查询时不会失去性能(查询在大型表中运行花费了很长时间)
错误代码:
SELECT country_name AS Country
,Count(*) OVER (PARTITION BY country_name) AS Count_C
,province AS Province
,Count(*) OVER (PARTITION BY province) AS Count_P
FROM country_list
GROUP BY country_name
,province
ORDER BY 1 DESC
,4 DESC
答案 0 :(得分:2)
我认为您只想使用一个窗口函数进行聚合:
void addbooktype(){
System.out.println("You chose: " + this.kind);
System.out.println("Adding to the list...");
booklist[bookcounter++] = this;
}