Worksheet 1 Group Functions Answers

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Worksheet 1: Group Functions

1.
a. 0.222857
b. 0.6729
c. The first query counts everything, while the second query counts
whatever is null.
2.
a. Dept_id is an alias. It is the column header name. A foreign key.
3.
a. We cannot use WHERE to restrict a group. Instead, HAVING is used.

4.
a. True
b. False
c. True

5. SELECT ROUND (MAX(salary),0) 'Max', ROUND (MIN(salary),0) 'Min',


ROUND (SUM(salary),0) 'Sum', ROUND (AVG(salary),0) 'Average' FROM
employees;

Challenge Questions:
6. SELECT job_id, COUNT(*) FROM employees GROUP BY job_id;
7. SELECT COUNT(DISTINCT manager_id) 'Number of Managers' FROM
employees;

8. SELECT manager_id, MIN (salary) FROM employees WHERE manager_id IS


NOT NULL GROUP BY manager_id HAVING MIN (salary) > 6000 ORDER BY
MIN (salary) DESC;

You might also like