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
20 changes: 13 additions & 7 deletions SQL Deep Dive/Date Filtering/questions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,43 @@
* Question: Get me all the employees above 60, use the appropriate date functions
*/

SELECT * FROM employees;
SELECT age(birth_date)
FROM employees
WHERE (EXTRACT(YEAR FROM age(birth_date))) > 60/

/*
* DB: Employees
* Table: employees
* Question: How many employees where hired in February?
*/

SELECT * FROM employees;
SELECT count(emp_no)
FROM employees
WHERE EXTRACT (month from hire_date) = 2

/*
* DB: Employees
* Table: employees
* Question: How many employees were born in november?
*/

SELECT * FROM employees;
FROM employees
WHERE EXTRACT (month from birth_date) = 11

/*
* DB: Employees
* Table: employees
* Question: Who is the oldest employee? (Use the analytical function MAX)
*/

SELECT * FROM employees;
SELECT MAX(AGE(birth_date))
FROM employees;

/*
* DB: Store
* Table: orders
* Question: How many orders were made in January 2004?
*/

SELECT * FROM orders;
SELECT COUNT(orderid)
FROM orders
WHERE DATE_TRUNC('month', orderdate) = date '2004-01-01';