Hi! Could we please enable some services and cookies to improve your experience and our website?

SQLize | PHPize | SQLtest

Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code

A A A
Login    Share code      Blog   FAQ
Copy Format Clear
create table t (id int, year int, value int); insert into t values (1, 2022, 10), (1, 2020, 5), (2, 2019, 10), (2, 2021, 4), (3, 2018, 2), (3, 2017, 10); with row_numbers as ( select *, row_number() over (partition by value order by year desc) rn from t ) select id, year, value from row_numbers where rn = 1;

Stuck with a problem? Got Error? Ask AI support!

Copy Clear