2

I'm trying to execute this code but it says i'm missing something in row_number() expression which I'm not able to figure out at all.

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;
Mureinik
  • 297,002
  • 52
  • 306
  • 350
gireesh4manu
  • 109
  • 2
  • 12

2 Answers2

2

There shouldn't be a comma between the partition by clause and the order by clause. Just remove it and you should be OK:

row_number() over (partition by length(s.city) order by s.city)
-- Comma removed here ------------------------^
Mureinik
  • 297,002
  • 52
  • 306
  • 350
1

Your query can be simplified:

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);

I removed r1 because it is not being used.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786