TASK 10 Queries with aggregates (Pt. 1) Flashcards
(4 cards)
1
Q
Find the longest time that an employee has been at the studio
A
SELECT MAX(years_employed) as Max_years_employed
FROM employees;
2
Q
For each role, find the average number of years employed by employees in that role
A
SELECT role, AVG(years_employed) as Average_years_employed
FROM employees
GROUP BY role;
3
Q
Find the total number of employee years worked in each building
A
SELECT building, SUM(years_employed) as Total_years_employed
FROM employees
GROUP BY building;
4
Q
Example
A
SELECT AGG_FUNC(column_or_expression) AS aggregate_description, …
FROM mytable
WHERE constraint_expression;