From 0cc727b7b0c19ceb4cbd6026826b54d043eda4b1 Mon Sep 17 00:00:00 2001 From: Uzziah Ngogela <127846165+UzMatic@users.noreply.github.com> Date: Thu, 21 Nov 2024 11:16:26 +0200 Subject: [PATCH 1/2] Update questions.sql --- SQL Deep Dive/Distinct/questions.sql | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/SQL Deep Dive/Distinct/questions.sql b/SQL Deep Dive/Distinct/questions.sql index 1ae66a7..c883957 100644 --- a/SQL Deep Dive/Distinct/questions.sql +++ b/SQL Deep Dive/Distinct/questions.sql @@ -4,7 +4,8 @@ * Question: What unique titles do we have? */ -SELECT * FROM titles; +SELECT DISTINCT(title) + FROM titles /* @@ -12,8 +13,8 @@ SELECT * FROM titles; * Table: employees * Question: How many unique birth dates are there? */ - -SELECT * FROM employees; +SELECT DISTINCT(COUNT(birth_date)) + FROM Employees; /* * DB: World @@ -21,6 +22,7 @@ SELECT * FROM employees; * Question: Can I get a list of distinct life expectancy ages * Make sure there are no nulls */ - -SELECT * FROM country; - +SELECT DISTINCT(lifeexpectancy) +FROM country +WHERE lifeexpectancy is not null +order BY lifeexpectancy ASC; From fa2049bb7a92b2a6c3787f12524f1b817b6a80c2 Mon Sep 17 00:00:00 2001 From: Uzziah Ngogela <127846165+UzMatic@users.noreply.github.com> Date: Thu, 21 Nov 2024 11:53:14 +0200 Subject: [PATCH 2/2] Update questions.sql --- SQL Deep Dive/Order By/questions.sql | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/SQL Deep Dive/Order By/questions.sql b/SQL Deep Dive/Order By/questions.sql index ccd4ac6..40c0860 100644 --- a/SQL Deep Dive/Order By/questions.sql +++ b/SQL Deep Dive/Order By/questions.sql @@ -3,6 +3,9 @@ * Table: employees * Question: Sort employees by first name ascending and last name descending */ +SELECT first_name, last_name +FROM employees +ORDER BY first_name ASC, last_name desc; /* @@ -10,6 +13,9 @@ * Table: employees * Question: Sort employees by age */ +SELECT first_name, last_name, EXTRACT(YEAR FROM AGE(birth_date)) AS Age +FROM employees +ORDER BY age; /* @@ -17,3 +23,7 @@ * Table: employees * Question: Sort employees who's name starts with a "k" by hire_date */ +SELECT * +FROM employees +WHERE first_name ILIKE 'k%' +ORDER BY hire_date;