From 687602ff0409631fd44d019f167ced0409394c92 Mon Sep 17 00:00:00 2001 From: anton Date: Tue, 13 Jan 2026 19:58:11 +0300 Subject: [PATCH] update filtr tasks --- .../filtration tasks/filtr_code.sql | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 avysokih/postgresql/filtration tasks/filtr_code.sql diff --git a/avysokih/postgresql/filtration tasks/filtr_code.sql b/avysokih/postgresql/filtration tasks/filtr_code.sql new file mode 100644 index 0000000..fc1d99b --- /dev/null +++ b/avysokih/postgresql/filtration tasks/filtr_code.sql @@ -0,0 +1,46 @@ +create table products_extended( +id INT primary key, +name TEXT, +category TEXT, +price DECIMAL, +in_stock BOOLEAN, +email_support TEXT +); + +INSERT INTO products_extended (id, name, category, price, in_stock, email_support) VALUES +(1, 'iPhone 14', 'smartphone', 799, TRUE, 'iphone@apple.com'), +(2, 'MacBook Air', 'laptop', 1199, FALSE, NULL), +(3, 'Galaxy S22', 'smartphone', 699, TRUE, 'galaxy@support.com'), +(4, 'ThinkPad X1', 'laptop', 1399, TRUE, 'thinkpad@lenovo.com'), +(5, 'iPad Pro', 'tablet', 999, FALSE, 'ipad@apple.com'), +(6, 'Kindle Paperwhite', 'ebook_reader', 149, TRUE, NULL), +(7, 'Mi Band 7', 'smartwatch', 49, TRUE, 'miband@xiaomi.com'), +(8, 'Surface Pro', 'tablet', 1299, TRUE, 'surface@microsoft.com'), +(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; + +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; + +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; + +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; + +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; + +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 +order by price desc; \ No newline at end of file