触发以下查询时出现ORA-00937
错误。
查询:
SELECT *
FROM
(SELECT streetid,
roadid,
LISTAGG(longitude ,',') WITHIN GROUP ( ORDER BY sequence_number) long_agg ,
LISTAGG(latitude ,',') WITHIN GROUP ( ORDER BY sequence_number) lat_agg ,
rownum r
FROM linkstable
WHERE areaid = 100
group by strretid,roadid )
WHERE r > 100 AND r < 200;
错误:
ORA-00937: not a single-group group function
00937. 00000 - "not a single-group group function"
答案 0 :(得分:3)
这是您的查询:
select *
from (select t.*, rownum as r
from (select streetid, roadid,
LISTAGG(longitude ,',') WITHIN GROUP (ORDER BY sequence_number) as long_agg ,
LISTAGG(latitude ,',') WITHIN GROUP (ORDER BY sequence_number) as lat_agg
from linkstable
where areaid = 100
) t
) t
where r > 100 and r < 200;
您使用LISTAGG()
作为聚合函数,但没有group by
。因此,所有其他列都是无效的,因为它们不是聚合函数的参数。也许你打算:
select *
from (select streetid, roadid,
LISTAGG(longitude ,',') WITHIN GROUP (ORDER BY sequence_number) as long_agg ,
LISTAGG(latitude ,',') WITHIN GROUP (ORDER BY sequence_number) as lat_agg ,
rownum r
from linkstable
where areaid = 100
group by streetid, roadid
)
where r > 100 and r < 200;
答案 1 :(得分:1)
扩展Gordon的解决方案,使用rownum
的解决方法WITH street_list as
(
SELECT streetid,
roadid,
LISTAGG(longitude ,',') WITHIN GROUP ( ORDER BY sequence_number) long_agg ,
LISTAGG(latitude ,',') WITHIN GROUP ( ORDER BY sequence_number) lat_agg ,
FROM linkstable
WHERE areaid = 100
group by strretid,roadid
),
street_list_numbered as
(
SELECT rownum r,streetid,roadid, long_agg,lat_agg
FROM street_list
)
SELECT * FROM street_list_numbered
WHERE r > 100 and r < 200;