SQLize Online / PHPize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
create table t(user_id int, col2 numeric, col3 numeric); insert into t(user_id, col2, col3) -- values(1,1,4), (1,2,4), (1,3,4), (1,4,4) values (1,4,4), (1,4,4), (1,4,4), (1,4,4), (2,1,4), (2,4,4), (2,4,4), (2,4,4), (3,1,4), (3,2,3), (3,3,2), (3,4,1) -- values(1,1,2), (1,2,2) ; select * from t; with numbered_rows as ( select *, row_number() over(partition by user_id order by col2) as rn from t ) select * from numbered_rows where rn < 4 order by user_id, rn;
Stuck with a problem? Got Error? Ask ChatGPT!
Copy Clear