SQLize Online / PHPize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
create table t (id int, year int, value int); insert into t values (1, 2022, 10),(1, 2022, 11), (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 ChatGPT!

Copy Clear