From d7435d1e10f8700c7f1de81669969e3c04faa67b Mon Sep 17 00:00:00 2001 From: anton Date: Fri, 16 Jan 2026 12:31:08 +0300 Subject: [PATCH] command oreders solve --- .../command order/command_order.sql | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 avysokih/postgresql/command order/command_order.sql diff --git a/avysokih/postgresql/command order/command_order.sql b/avysokih/postgresql/command order/command_order.sql new file mode 100644 index 0000000..116fd41 --- /dev/null +++ b/avysokih/postgresql/command order/command_order.sql @@ -0,0 +1,53 @@ +/*Задача 1: Какой будет порядок выполнения у запросов? + +SELECT name, age +FROM users +WHERE is_active = true AND country = 'Canada' +ORDER BY age +LIMIT 3; + +*/ + +1. FROM users +2. WHERE is_active = true AND country = 'Canada' +3. SELECT name, age +4. ORDER BY age +5. LIMIT 3 + + /* +SELECT country, COUNT(*) AS active_users +FROM users +WHERE is_active = true +GROUP BY country +HAVING COUNT(*) > 1; + */ + + 1. FROM users + 2. WHERE is_active = true + 3. GROUP BY country + 4. HAVING COUNT(*) > 1 + 5. SELECT country, COUNT(*) AS active_users + + /* +SELECT country, AVG(age) AS avg_age +FROM users +GROUP BY country +HAVING COUNT(*) >= 3 AND AVG(age) > 25; + */ + + 1. FROM users + 2. GROUP BY country + 3. HAVING COUNT(*) >= 3 AND AVG(age) > 25 + 4. SELECT country, AVG(age) AS avg_age + + /* +SELECT name, age +FROM users +WHERE is_active = false AND age > 30 +ORDER BY name; + */ + + 1. FROM users + 2. WHERE is_active = false AND age > 30 + 3. SELECT name, age + 4. ORDER BY name \ No newline at end of file