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
11 changes: 6 additions & 5 deletions SQL Deep Dive/Date Filtering/questions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,38 @@
* 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;
SELECT count(birth_date) FROM employees WHERE birth_date < now() - interval '61 years';

/*
* 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 emp_no)) = 2;

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

SELECT * FROM employees;
SELECT count(birth_date) 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';