Files
avkalyanov/SQL/base_sql.sql
2026-04-26 10:53:07 +03:00

98 lines
1.9 KiB
SQL
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
-- Задание 1 — Спроектируй «карточку пользователя»
-- Ты делаешь экран “Пользователи” в админке и решаешь, какие поля там важны.
select
id,
name,
country,
created_at,
email
from
users
order by
created_at desc,
name asc;
-- Задание 2 — Сегментация по странам (с выбором)
-- Маркетолог хочет понять, какая страна сейчас интереснее.
select
id,
name,
country
from
users
where
country = 'US'
order by
name asc;
select
id,
name,
country
from
akalyanov.users
where
country = 'UK'
order by
name asc;
-- Задание 3 — Контакты для рассылки (думать про качество)
-- Нужно сделать список email для рассылки так, чтобы его не стыдно было отдавать маркетологу.
select
id,
name,
email
from
users
where
email is not null
order by
name;
select
DISTINCT LOWER(email) as email_lower
from
users
where
email is not null
order by
email_lower;
-- Задание 4 — Новички и активность
-- «Тебе нужно посмотреть, кто пришёл недавно и кого стоит “подогреть”.»
select
id,
name,
created_at
from
users
where
created_at > '2024-01-11'
order by
created_at desc;
select
id,
name,
created_at
from
users
where
created_at > '2024-01-11'
order by
created_at desc
limit
3;
-- Оффсет используется для пагинации
select
id,
name,
created_at
from
users
where
created_at > '2024-01-11'
order by
created_at desc
limit
2 offset 1;