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; 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;