Пользователи без профиля

SQLJunior5 минпроверка — Спринтзапрос · PostgreSQL14-t026

Схема: users (id, username, email, is_active, created_at) и profiles (id, user_id, first_name, last_name, gender, birthdate).

Запрос 1: выведи id всех пользователей, у которых нет ни одного профиля.

schema.sqlsql
1CREATE TABLE users (2    id         int     PRIMARY KEY,3    username   text    NOT NULL,4    email      text    NOT NULL,5    is_active  boolean NOT NULL DEFAULT true,6    created_at timestamptz NOT NULL DEFAULT now()7);8CREATE TABLE profiles (9    id         int  PRIMARY KEY,10    user_id    int  REFERENCES users (id),11    first_name text,12    last_name  text,13    gender     text,14    birthdate  date15);16INSERT INTO users (id, username, email, is_active) VALUES17    (1, 'one', '1@ex.com', true), (2, 'two', '2@ex.com', true), (3, 'three', '3@ex.com', true),18    (4, 'four', '4@ex.com', true), (5, 'five', '5@ex.com', false);19-- 1: один профиль, 2 и 5: нет, 3: два, 4: три; профиль 10 — «осиротевший» без user_id20INSERT INTO profiles (id, user_id, first_name) VALUES21    (1, 1, 'A'), (2, 3, 'B'), (3, 3, 'C'), (4, 4, 'D'), (5, 4, 'E'), (6, 4, 'F'), (10, NULL, 'X');
⌘ Enter — проверить