bot50
2026-04-28 14:42:24 +00:00
commit 144001e997
12 changed files with 153 additions and 0 deletions

28
11.sql Normal file
View File

@@ -0,0 +1,28 @@
-- write a SQL query to find the 10 least expensive players per hit in 2001.
-- Your query should return a table with three columns, one for the players first names, one of their last names,
-- and one called “dollars per hit”.
-- You can calculate the “dollars per hit” column by dividing a players 2001 salary by the number of hits they made
-- in 2001. Recall you can use AS to rename a column.
-- Dividing a salary by 0 hits will result in a NULL value. Avoid the issue by filtering out players with 0 hits.
-- Sort the table by the “dollars per hit” column, least to most expensive. If two players have the same “dollars per
-- hit”, order by first name, followed by last name, in alphabetical order.
-- As in 10.sql, ensure that the salarys year and the performances year match.
-- You may assume, for simplicity, that a player will only have one salary and one performance in 2001.
SELECT
p."first_name",
p."last_name",
(s."salary" / perf."H") AS "dollar per hit"
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"
WHERE
s."year" = '2001'
AND perf."H" > 0
ORDER BY
"dollars per hit" ASC,
p."first_name" ASC,
p."last_name" ASC
LIMIT 10;