SQLize Online / PHPize Online

A A A
Share   Donate   Blog   Popular
Copy Format Clear
create table `groups` ( id int, group_id int, invited_by_user_id int, name varchar(64), posts_qty int ); insert into `groups` (id, name) values (1, 'Группа 1'), (2, 'Группа 2'); create table users ( id int, group_id int, invited_by_user_id int, name varchar(64), posts_qty int ); insert into users ( id, group_id, invited_by_user_id, name, posts_qty ) values ( 1, 1, 0, 'Пользователь 1', 0 ), ( 2, 1, 1, 'Пользователь 2', 2 ), ( 3, 1, 2, 'Пользователь 3', 5 ), ( 4, 2, 3, 'Пользователь 4', 7 ), ( 5, 2, 4, 'Пользователь 5', 1 ); with ranked as ( select users.*, rank() over (partition by group_id order by posts_qty desc) r from users ) select * from ranked where r = 1;
Stuck with a problem? Need help? Ask professionals on our Telegram channel!
Join the channel
Your quersion is posted.
Join our Telegram channel and get answers.
Send
Copy