0
我想为此使用分析,因为我有其他几个相似的统计数据,我想要 报告。这是一个正确使用'分区'的问题吗?
问:使用Oracle Analytics,我怎样才能在每个机场只有一行?
with detail_records as
(select 1 as passenger_id, 'ATL' as airport, 'E4' as gate, 10 as luggage_weight from dual union all
select 2 as passenger_id, 'ATL' as airport, 'E4' as gate, 25 as luggage_weight from dual union all
select 2 as passenger_id, 'SFO' as airport, 'E4' as gate, 20 as luggage_weight from dual union all
select 3 as passenger_id, 'SFO' as airport, 'E4' as gate, 30 as luggage_weight from dual union all
select 4 as passenger_id, 'SFO' as airport, 'E4' as gate, 40 as luggage_weight from dual
)
select airport,
count(*) over (partition by airport) as airport_count,
sum(luggage_weight) over (partition by airport, gate) as a_g_weight
from detail_records
where gate='E4'
结果
AIRPORT AIRPORT_COUNT A_G_WEIGHT
ATL 2 35
ATL 2 35
SFO 3 90
SFO 3 90
SFO 3 90
预期的效果
Airport Airport_count A_G_WEIGHT
ATL 2 35
SFO 3 90
尝试'选择DISTINCT机场,...' –
如果您通过单个门进行过滤,那么该列的分区不会添加任何内容;如果你通过多个门(或全部)过滤,那么你将有多个'a_g_weight'值,没有任何解释原因。 –