Files
me50/9.sql

15 lines
585 B
SQL
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
-- write a SQL query to find the 5 lowest paying teams (by average salary) in 2001.
-- Round the average salary column to two decimal places and call it “average salary”.
-- Sort the teams by average salary, least to greatest.
-- Your query should return a table with two columns, one for the teams names and one for their average salary.
SELECT
t."name",
ROUND(AVG(s."salary"), 2) AS "average salary"
FROM "teams" AS t
JOIN "salaries" AS s
ON s."team_id" = t."id"
WHERE s."year" = '2001'
GROUP BY t."id", t."name"
ORDER BY "average salary" ASC
LIMIT 5;