Advertisement
Zhakey567

Untitled

Feb 5th, 2023
1,290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. create table users (
  2.   id bigint primary key,
  3.   name varchar not null
  4. );
  5.  
  6. create table contests (
  7.   id bigint primary key,
  8.   name varchar not null
  9. );
  10.  
  11. create table problems (
  12.   id bigint primary key,
  13.   contest_id bigint,
  14.   code varchar not null,
  15.   constraint fk_problems_contest_id foreign key (contest_id) references contests (id)
  16. );
  17.  
  18. create unique index on problems (contest_id, code);
  19.  
  20. create table submissions (
  21.   id bigint primary key,
  22.   user_id bigint,
  23.   problem_id bigint,
  24.   success boolean not null,
  25.   submitted_at timestamp not null,
  26.   constraint fk_submissions_user_id foreign key (user_id) references users (id),
  27.   constraint fk_submissions_problem_id foreign key (problem_id) references problems (id)
  28. );
  29.  
  30. insert into users
  31. values (1, 'Marie Curie'),
  32.        (2, 'Stephen Hawking'),
  33.        (3, 'Ada Lovelace'),
  34.        (4, 'Albert Einstein'),
  35.        (5, 'Archimedes');
  36.  
  37. insert into contests
  38. values (1, 'Sandbox-Juniors'),
  39.        (2, 'Sandbox-Seniors'),
  40.        (3, 'Contest-Juniors'),
  41.        (4, 'Contest-Seniors');
  42.  
  43. insert into problems
  44. values (1, 1, 'A'),
  45.        (2, 2, 'A'),
  46.        (3, 3, 'A'),
  47.        (4, 3, 'B'),
  48.        (5, 4, 'A'),
  49.        (6, 4, 'B');
  50.  
  51. insert into submissions
  52. values (1, 2, 2, false, '2023-02-05 11:01:00'),
  53.        (2, 2, 2, true, '2023-02-05 11:02:00'),
  54.        (3, 2, 6, true, '2023-02-05 11:03:01'),
  55.        (4, 2, 1, true, '2023-02-05 11:04:00'),
  56.        (5, 2, 1, true, '2023-02-05 11:05:00'),
  57.        (6, 3, 6, true, '2023-02-05 11:06:00'),
  58.        (17, 1, 6, true, '2023-02-05 11:03:00'),
  59.        (8, 1, 2, true, '2023-02-05 11:08:00'),
  60.        (9, 1, 1, false, '2023-02-05 11:09:00'),
  61.        (10, 3, 1, false, '2023-02-05 11:10:00'),
  62.        (11, 5, 5, false, '2023-02-05 11:11:00'),
  63.        (13, 2, 6, true, '2023-02-05 11:03:00'),
  64.        (14, 3, 6, false, '2023-02-05 11:05:59'),
  65.        (15, 1, 6, true, '2023-02-05 11:04:00');
  66.  
  67.  
  68.  id | contest_id | code
  69. ----+------------+------
  70.   2 |          2 | A
  71.   6 |          4 | B
  72. (2 rows)
  73.  
  74.  
  75.  
  76. create table users (
  77.   id bigint primary key,
  78.   name varchar not null
  79. );
  80.  
  81. create table contests (
  82.   id bigint primary key,
  83.   name varchar not null
  84. );
  85.  
  86. create table problems (
  87.   id bigint primary key,
  88.   contest_id bigint,
  89.   code varchar not null,
  90.   constraint fk_problems_contest_id foreign key (contest_id) references contests (id)
  91. );
  92.  
  93. create unique index on problems (contest_id, code);
  94.  
  95. create table submissions (
  96.   id bigint primary key,
  97.   user_id bigint,
  98.   problem_id bigint,
  99.   success boolean not null,
  100.   submitted_at timestamp not null,
  101.   constraint fk_submissions_user_id foreign key (user_id) references users (id),
  102.   constraint fk_submissions_problem_id foreign key (problem_id) references problems (id)
  103. );
  104.  
  105. insert into users
  106. values (1, 'Olivia'),
  107.        (2, 'Henry'),
  108.        (3, 'Lucas'),
  109.        (4, 'John'),
  110.        (5, 'Charlotte'),
  111.        (6, 'Henry');
  112.  
  113. insert into contests
  114. values (3, 'Main'),
  115.        (1, 'Practice');
  116.  
  117. insert into problems
  118. values (1, 3, 'A'),
  119.        (2, 3, 'B'),
  120.        (3, 1, 'A');
  121.  
  122. insert into submissions
  123. values (10, 3, 2, false, '2023-02-05 11:05:12'),
  124.        (20, 3, 2, true, '2023-02-05 11:07:49'),
  125.        (30, 3, 2, true, '2023-02-05 11:07:49'),
  126.        (40, 3, 1, false, '2023-02-05 11:01:32'),
  127.        (50, 3, 1, false, '2023-02-05 11:11:46'),
  128.        (60, 3, 1, false, '2023-02-05 11:27:05'),
  129.        (70, 6, 2, false, '2023-02-05 11:04:00'),
  130.        (80, 6, 2, true, '2023-02-05 11:05:00'),
  131.        (90, 6, 2, false, '2023-02-05 11:06:00'),
  132.        (100, 6, 2, true, '2023-02-05 11:07:00'),
  133.        (110, 6, 1, false, '2023-02-05 11:08:00'),
  134.        (120, 6, 1, true, '2023-02-05 11:09:00'),
  135.        (130, 2, 2, false, '2023-02-05 11:00:01'),
  136.        (150, 5, 1, false, '2023-02-05 11:07:48'),
  137.        (160, 5, 1, true, '2023-02-05 11:07:49'),
  138.        (170, 5, 1, true, '2023-02-05 11:07:50'),
  139.        (180, 1, 3, false, '2023-02-04 15:00:01'),
  140.        (190, 1, 3, true, '2023-02-04 15:00:01'),
  141.        (200, 5, 3, true, '2023-02-04 15:00:01'),
  142.        (210, 5, 3, false, '2023-02-04 15:00:01'),
  143.        (220, 2, 3, false, '2023-02-04 15:00:01'),
  144.        (230, 6, 3, false, '2023-02-04 15:00:01'),
  145.        (240, 6, 3, false, '2023-02-04 15:00:01');
  146.  
  147.  
  148.  id | contest_id | code
  149. ----+------------+------
  150.   1 |          3 | A
  151.   2 |          3 | B
  152.   3 |          1 | A
  153. (3 rows)
  154.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement