Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback, please email oracle-forums_moderators_us@oracle.com

Window Functions: Using current row value to find elements

Tina PediloOct 28 2023

Hey guys, is it possible to refer to columns from the current row when filtering using Window Functions only?

Given this sample set from the URL, I want to get the first row id within the resultset,
whose id is equals to the current id multiplied by 2.

In this case only ids 11 and 12 should get an result,

11 => 22 and 12 => 24, since all other others do not fit this condition.

Thanks in advance and regards.

https://sqlime.org/#employees.db

SELECT *
, FIRST_VALUE(CASE WHEN #current_id*2 = id THEN id END) OVER (ORDER BY id)

FROM employees
Comments
Post Details