Files
me50/10.sql
2026-04-28 16:26:57 +02:00

28 lines
1.2 KiB
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.
-- To be precise, the table should include:
-- All players first names
-- All players last names
-- All players salaries
-- All players home runs
-- The year in which the player was paid that salary and hit those home runs
-- In 10.sql, write a query to return just such a table.
-- Your query should return a table with five columns, per the above.
-- Order the results, first and foremost, by players IDs (least to greatest).
-- Order rows about the same player by year, in descending order.
-- Consider a corner case: suppose a player has multiple salaries or performances for a given year.
-- Order them first by number of home runs, in descending order, followed by salary, in descending order.
-- Be careful to ensure that, for a single row, the salarys year and the performances year match.
SELECT p."first_name", p."last_name", s."salary", perf."HR", s."year"
FROM "players" AS p
JOIN "salaries" AS s
ON s."player_id" = p."id"
JOIN "performances" AS perf
ON perf."player_id" = p."id"
AND perf."year" = s."year"
ORDER BY
p."id" ASC,
s."year" DESC,
perf."year" DESC
s."salary" DESC;