You have to be careful with rownum
, as you have to order the results before you try to evaluate that, and you can't use it to compare with equality except for = 1
. You may find this interesting.
You could use analytic functions to get the row number and overall row count:
select lat_n, city, row_number() over (order by lat_n) as rn, count(*) over () as cnt
from station
and then use that in a subquery (inline view or CTE) to filter:
select lat_n, city
from (
select lat_n, city, row_number() over (order by lat_n) as rn, count(*) over () as cnt
from station
)
where rn = ceil(cnt/2)
You've said the column is a number, but with the trailing zeros it looks like you might be storing it as a string; in which case you may need to convert to a number before ordering.