Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions SQL Deep Dive/Like Operator/questions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
* 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 like 'M%'


/*
Expand All @@ -14,6 +15,8 @@ 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(emp_no) FROM employees
WHERE first_name ILIKE 'A%R';


/*
Expand All @@ -22,7 +25,8 @@ 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%';


/*
Expand All @@ -31,6 +35,8 @@ 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%';


/*
Expand All @@ -40,4 +46,6 @@ 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%';