update filtr tasks: add comments
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
-- Создание и заполнение таблицы
|
||||
|
||||
create table products_extended(
|
||||
id INT primary key,
|
||||
name TEXT,
|
||||
@@ -19,27 +21,83 @@ INSERT INTO products_extended (id, name, category, price, in_stock, email_suppor
|
||||
(9, 'Honor Pad X9', 'tablet', 219, TRUE, 'honor@support.com'),
|
||||
(10, 'Dell XPS 13', 'laptop', 1099, FALSE, 'dell@support.com');
|
||||
|
||||
select * from products_extended
|
||||
where in_stock = true and category not in ('smartwatch', 'ebookreader') and price between 300 and 1300;
|
||||
/*
|
||||
Задача 1:
|
||||
Выведи все товары, которые:
|
||||
- в наличии
|
||||
- НЕ относятся к `smartwatch` и `ebook_reader`
|
||||
- стоят от 300 до 1300
|
||||
И для них посчитай:
|
||||
1. price с наценкой 10%
|
||||
2. price с НДС 20%
|
||||
3. Статус: если email_support IS NULL, подставь нет почты, иначе — сам email
|
||||
*/
|
||||
|
||||
|
||||
select name, category, price, price * 1.1 as price_with_markup, price * 1.2 as price_with_vat, coalesce(email_support, 'нет почты') as status
|
||||
from products_extended
|
||||
where in_stock = true and category not in ('smartwatch', 'ebookreader') and price between 300 and 1300;
|
||||
|
||||
/*
|
||||
Задача 2:
|
||||
Найти все товары:
|
||||
1. У которых цена меньше 150 или больше 1200
|
||||
2. У которых** есть email поддержки
|
||||
Для каждого выведи:
|
||||
1. Название
|
||||
2. Категорию
|
||||
3. Email
|
||||
4. Цену с прибавкой 25%
|
||||
5. Отметку `premium` — если цена > 1000
|
||||
*/
|
||||
|
||||
select name, category, email_support, price * 1.25 as price_25, (price> 1000) as premium
|
||||
from products_extended
|
||||
where (price < 150 or price > 1200) and email_support is not null
|
||||
order by premium;
|
||||
|
||||
/*
|
||||
Задача 3:
|
||||
Найди все товары:
|
||||
- где категория — `smartphone`, `laptop`, `tablet`
|
||||
- название НЕ содержит `'i'` (чтобы исключить Apple)
|
||||
- цена от 500 до 1300
|
||||
Выведи:
|
||||
- `id`, `name`, `category`, `price`
|
||||
- отсортируй по `id`
|
||||
*/
|
||||
|
||||
select id, name, category, price
|
||||
from products_extended
|
||||
where category in('smartphone', 'laptop', 'tablet') and name not like '%i%' and price between 500 and 1300
|
||||
order by id desc;
|
||||
|
||||
/*
|
||||
Задача 4:
|
||||
Найди товары, у которых:
|
||||
- email_support IS NULL
|
||||
- они в наличии
|
||||
- стоят менее 800
|
||||
Выведи:
|
||||
- `name`, `category`, `price`
|
||||
- добавь колонку `comment`: `'нет поддержки'`
|
||||
*/
|
||||
|
||||
select name, category, price, coalesce (email_support, 'нет поддержки') as comment
|
||||
from products_extended
|
||||
where email_support is null and in_stock is not null and price < 800;
|
||||
|
||||
/*
|
||||
Задача 5:
|
||||
Найди товары, у которых:
|
||||
- название заканчивается на `'Pro'` ИЛИ содержит `'X'` внутри (например, `X1`, `XPS`)
|
||||
- в наличии
|
||||
- с ценой > 700
|
||||
Выведи:
|
||||
- `name`, `category`, `price`
|
||||
- флаг `premium` — `true`, если `price > 1000`, иначе `false`
|
||||
*/
|
||||
|
||||
select name, category, price, (price>1000) as premium
|
||||
from products_extended
|
||||
where (name like '%Pro%' or name like '%X%') and in_stock is true and price > 700
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 99 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 73 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 64 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 58 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 112 KiB |
Reference in New Issue
Block a user