Skip to content

Instantly share code, notes, and snippets.

@briu
Last active July 9, 2019 15:42
Show Gist options
  • Save briu/20c3ce010c11a54538139d44685af269 to your computer and use it in GitHub Desktop.
Save briu/20c3ce010c11a54538139d44685af269 to your computer and use it in GitHub Desktop.
выбрать игру для пользователя с наибольшим количеством часов
create database tmp_db1;
\c tmp_db1;
CREATE TABLE users (
id integer,
email varchar(255)
);
CREATE TABLE stats (
id integer,
hours integer,
date date,
game_id integer,
user_id integer
);
CREATE TABLE games (
id integer,
title varchar(255)
);
INSERT into users (email) values ('foo@bar.com'), ('foo2@bar.com');
INSERT into games (title) values ('game1'), ('game2');
INSERT into stats(hours, date, game_id, user_id) values (3, '2018-09-11', 1, 1);
INSERT into stats(hours, date, game_id, user_id) values (13, '2018-09-11', 2, 2);
INSERT into stats(hours, date, game_id, user_id) values (1, '2018-09-12', 1, 1);
INSERT into stats(hours, date, game_id, user_id) values (5, '2018-09-12', 2, 2);
INSERT into stats(hours, date, game_id, user_id) values (8, '2018-09-13', 1, 1);
INSERT into stats(hours, date, game_id, user_id) values (6, '2018-09-13', 2, 2);
drop database tmp_db1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment