;with data as ( select t.*, row_number() over (order by foo) rn from yourtable )
select *
from data
where rn = ( select ( max(x.rn) / 2 ) + 1 from data x)
now, what if the count(*) returns 2 (an even number...), what row to return? row 1 or row 2 ?;with data as ( select t.*, row_number() over (order by foo) rn from yourtable )
select *
from data
where rn = ( select floor( max(x.rn) / 2 ) + 1 from data x)
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Have a better answer? Share it in a comment.
From novice to tech pro — start learning today.
Open in new window