diff --git a/avysokih/postgresql/filtration tasks/filtr_code.sql b/avysokih/postgresql/filtration tasks/filtr_code.sql index fc1d99b..ad69680 100644 --- a/avysokih/postgresql/filtration tasks/filtr_code.sql +++ b/avysokih/postgresql/filtration tasks/filtr_code.sql @@ -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 diff --git a/avysokih/postgresql/filtration tasks/filtration_task_1.JPG b/avysokih/postgresql/filtration tasks/filtration_task_1.JPG deleted file mode 100644 index 563fa42..0000000 Binary files a/avysokih/postgresql/filtration tasks/filtration_task_1.JPG and /dev/null differ diff --git a/avysokih/postgresql/filtration tasks/filtration_task_2.JPG b/avysokih/postgresql/filtration tasks/filtration_task_2.JPG deleted file mode 100644 index 9cb9284..0000000 Binary files a/avysokih/postgresql/filtration tasks/filtration_task_2.JPG and /dev/null differ diff --git a/avysokih/postgresql/filtration tasks/filtration_task_3.JPG b/avysokih/postgresql/filtration tasks/filtration_task_3.JPG deleted file mode 100644 index 40b8fe4..0000000 Binary files a/avysokih/postgresql/filtration tasks/filtration_task_3.JPG and /dev/null differ diff --git a/avysokih/postgresql/filtration tasks/filtration_task_4.JPG b/avysokih/postgresql/filtration tasks/filtration_task_4.JPG deleted file mode 100644 index a31013b..0000000 Binary files a/avysokih/postgresql/filtration tasks/filtration_task_4.JPG and /dev/null differ diff --git a/avysokih/postgresql/filtration tasks/filtration_task_5.JPG b/avysokih/postgresql/filtration tasks/filtration_task_5.JPG deleted file mode 100644 index d333685..0000000 Binary files a/avysokih/postgresql/filtration tasks/filtration_task_5.JPG and /dev/null differ