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
22 changes: 20 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,9 @@
* 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 first_name, EXTRACT (YEAR FROM AGE(birth_date)) as "age"
FROM employees
WHERE first_name LIKE 'M%';


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





/*
Expand All @@ -22,7 +30,11 @@ 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(*)
FROM customers
WHERE CAST(zip AS TEXT) LIKE '%2%';

number of people with 2 in their zipcode is = 4211


/*
Expand All @@ -31,6 +43,9 @@ 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(*)
FROM customers
where cast(zip as text) LIKE '2_1%';


/*
Expand All @@ -39,5 +54,8 @@ SELECT ..., EXTRACT (YEAR FROM AGE(birth_date)) as "age" FROM employees;
* Question: Which states have phone numbers starting with 302?
* Replace null values with "No State"
* Expected output: https://imgur.com/AVe6G4c
*/
*/SELECT COALESCE(state, 'no state') AS State
FROM customers
WHERE phone LIKE '302%'