我使用rank()生成了报告。
select sa.COUNTRY,
sa.CITY,
to_char(sum(r.TOTAL_SERVICE_COST)) as Total_Service_Cost,
rank() OVER (PARTITION BY sa.COUNTRY
ORDER BY SUM(r.TOTAL_SERVICE_COST) Desc) as City_Rank_by_country
from ROUTESFACT r,SOURCEAIRPORT_DIM sa
where r.SOURCEAIRPORTID=sa.SOURCE_AIRPORTID
GROUP BY sa.COUNTRY,sa.CITY;
如您所见,窗口排序和散列分组未得到有效优化。 优化这个的最佳方法是什么?
答案 0 :(得分:1)
首先,使用正确的join
语法来纠正您的查询。一个整洁,正确编写的查询更容易改进:
select sa.COUNTRY, sa.CITY,
to_char(sum(r.TOTAL_SERVICE_COST)) as Total_Service_Cost,
rank() OVER (PARTITION BY sa.COUNTRY
ORDER BY SUM(r.TOTAL_SERVICE_COST) Desc
) as City_Rank_by_country
from ROUTESFACT r join
SOURCEAIRPORT_DIM sa
on r.SOURCEAIRPORTID = sa.SOURCE_AIRPORTID
group by sa.COUNTRY, sa.CITY;
我不确定他们会提供多少帮助,但索引是一种很好的开始方式:SOURCEAIRPORT_DIM(Country, City, SOURCE_AIRPORTID)
和ROUTESFACT(SOURCEAIRPORTID, TOTAL_SERVICE_COST)
。
这些可能有助于您的查询。