我正在尝试执行此代码,但它说我在row_number()
表达式中缺少某些内容,我根本无法弄清楚。
with summary as
(select s.city, length(s.city) as C_length,
row_number() over (partition by length(s.city), order by s.city)
as r1 from station s
where
length(s.city) = (SELECT min(LENGTH(s1.CITY)) FROM STATION s1)
or length(s.city) = (SELECT max(LENGTH(s2.CITY)) FROM STATION s2))
select su.city, su.C_length
from summary su;
partition by
子句和order by
子句之间不应该有逗号。只需删除它,您应该可以:
row_number() over (partition by length(s.city) order by s.city)
-- Comma removed here ------------------------^
您的查询可以简化:
with summary as (
select s.city, length(s.city) as C_length,
min(length(s.city)) over () as min_length,
max(length(s.city)) over () as max_length,
from station s
)
select su.city, su.C_length
from summary su
where c_length in (min_length, max_length);
我删除了r1
,因为它没有使用。