diff --git a/SQL Deep Dive/Like Operator/questions.sql b/SQL Deep Dive/Like Operator/questions.sql index 3d9f0f7..e510685 100644 --- a/SQL Deep Dive/Like Operator/questions.sql +++ b/SQL Deep Dive/Like Operator/questions.sql @@ -5,7 +5,7 @@ * Sample output: https://imgur.com/vXs4093 * Use EXTRACT (YEAR FROM AGE(birth_date)) we will learn about this in later parts of the course */ -SELECT ..., EXTRACT (YEAR FROM AGE(birth_date)) as "age" FROM employees; +SELECT emp_no, first_name, EXTRACT (YEAR FROM AGE(birth_date)) as "age" FROM employees where first_name ilike 'M%'; /* @@ -14,7 +14,7 @@ SELECT ..., EXTRACT (YEAR FROM AGE(birth_date)) as "age" FROM employees; * Question: How many people's name start with A and end with R? * Expected output: 1846 */ - +select count(empno) from employees where first_name ilike 'A%R'; /* * DB: Store @@ -22,8 +22,7 @@ SELECT ..., EXTRACT (YEAR FROM AGE(birth_date)) as "age" FROM employees; * Question: How many people's zipcode have a 2 in it?. * Expected output: 4211 */ - - +select count(customerid) from customers where zip::text like '%2'; /* * DB: Store @@ -31,7 +30,7 @@ SELECT ..., EXTRACT (YEAR FROM AGE(birth_date)) as "age" FROM employees; * Question: How many people's zipcode start with 2 with the 3rd character being a 1. * Expected output: 109 */ - +select count(customerid) from customers where zip::text like '2_1%'; /* * DB: Store @@ -40,4 +39,5 @@ SELECT ..., EXTRACT (YEAR FROM AGE(birth_date)) as "age" FROM employees; * Replace null values with "No State" * Expected output: https://imgur.com/AVe6G4c */ +select coalesce(state, "No state") as "STATE" from customers where phone::text like '302%';