From 2a73933131bb0acccdead90bea0a12bb50320225 Mon Sep 17 00:00:00 2001 From: Sibabalwe <102536140+Ngandana@users.noreply.github.com> Date: Wed, 20 Nov 2024 12:48:10 +0200 Subject: [PATCH] Update questions(my answers).sql --- SQL Deep Dive/Group By/questions.sql | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/SQL Deep Dive/Group By/questions.sql b/SQL Deep Dive/Group By/questions.sql index cd0c9d5..a9c8b2e 100644 --- a/SQL Deep Dive/Group By/questions.sql +++ b/SQL Deep Dive/Group By/questions.sql @@ -4,22 +4,31 @@ * Table: Employees */ -SELECT e.emp_no -FROM employees as e +SELECT hire_date, COUNT(emp_no) as "amount" +FROM employees +GROUP BY hire_date +ORDER BY "amount" DESC; /* * Show me all the employees, hired after 1991 and count the amount of positions they've had * Database: Employees */ -SELECT e.emp_no +SELECT e.emp_no, COUNT(t.title) AS "No of title" FROM employees as e +inner join titles as t on t.emp_no = e.emp_no +WHERE EXTRACT(YEAR FROM hire_date) > 1991 +GROUP BY e.emp_no +ORDER BY e.emp_no; /* * Show me all the employees that work in the department development and the from and to date. * Database: Employees */ - -SELECT e.emp_no +SELECT e.emp_no, de.from_date, de.to_date FROM employees as e +JOIN dept_emp AS de USING(emp_no) +WHERE de.dept_no = 'd005' +GROUP BY e.emp_no, de.from_date, de.to_date +ORDER BY e.emp_no, de.to_date;