From 1b2b61e7f79ba4922e2a2cf14c0a0c31a11cec27 Mon Sep 17 00:00:00 2001 From: bot50 Date: Tue, 28 Apr 2026 13:21:43 +0000 Subject: [PATCH] daviddoji-cs50/problems/2024/sql/moneyball@20260428T132143.821893296Z --- 1.sql | 8 ++++++++ 10.sql | 0 11.sql | 0 12.sql | 0 2.sql | 9 +++++++++ 3.sql | 15 +++++++++++++++ 4.sql | 13 +++++++++++++ 5.sql | 0 6.sql | 0 7.sql | 0 8.sql | 0 9.sql | 0 12 files changed, 45 insertions(+) create mode 100644 1.sql create mode 100644 10.sql create mode 100644 11.sql create mode 100644 12.sql create mode 100644 2.sql create mode 100644 3.sql create mode 100644 4.sql create mode 100644 5.sql create mode 100644 6.sql create mode 100644 7.sql create mode 100644 8.sql create mode 100644 9.sql diff --git a/1.sql b/1.sql new file mode 100644 index 0000000..d9cbba5 --- /dev/null +++ b/1.sql @@ -0,0 +1,8 @@ +-- write a SQL query to find the average player salary by year. +-- Sort by year in descending order. +-- Round the salary to two decimal places and call the column “average salary”. +-- Your query should return a table with two columns, one for year and one for average salary. +SELECT "year", ROUND(AVG("salary"), 2) AS "average salary" +FROM "salaries" +GROUP BY "year" +ORDER BY "year" DESC; diff --git a/10.sql b/10.sql new file mode 100644 index 0000000..e69de29 diff --git a/11.sql b/11.sql new file mode 100644 index 0000000..e69de29 diff --git a/12.sql b/12.sql new file mode 100644 index 0000000..e69de29 diff --git a/2.sql b/2.sql new file mode 100644 index 0000000..f672ed0 --- /dev/null +++ b/2.sql @@ -0,0 +1,9 @@ +-- write a SQL query to find Cal Ripken Jr.’s salary history. +-- Sort by year in descending order. +-- Your query should return a table with two columns, one for year and one for salary. +SELECT s."year", s."salary" +FROM "salaries" AS s +JOIN "players" AS p + ON s."player_id" = p."id" +WHERE p."first_name" = "Cal" AND p."last_name" LIKE "Ripken%" +ORDER BY "year" DESC; diff --git a/3.sql b/3.sql new file mode 100644 index 0000000..b84b33e --- /dev/null +++ b/3.sql @@ -0,0 +1,15 @@ +-- write a SQL query to find Ken Griffey Jr.’s home run history. +-- Sort by year in descending order. +-- Note that there may be two players with the name “Ken Griffey.” This Ken Griffey was born in 1969. +-- Your query should return a table with two columns, one for year and one for home runs. +SELECT perf."year", perf."hr" +FROM "performances" as perf +JOIN "players" AS p + ON perf."player_id" = p."id" +WHERE + p."first_name" = "Ken" + AND + p."last_name" LIKE "Griffey%" + AND + p."birth_year" = "1969" +ORDER BY "year" DESC; diff --git a/4.sql b/4.sql new file mode 100644 index 0000000..ad7e69e --- /dev/null +++ b/4.sql @@ -0,0 +1,13 @@ +-- write a SQL query to find the 50 players paid the least in 2001. +-- Sort players by salary, lowest to highest. +-- If two players have the same salary, sort alphabetically by first name and then by last name. +-- If two players have the same first and last name, sort by player ID. +-- Your query should return three columns, one for players’ first names, one for their last names, and one for their salaries. +SELECT + p."first_name", p."last_name", s."salary" +FROM "players" as p +JOIN "salaries" as s + ON s."player_id" = p."id" +WHERE s."year" = "2001" +ORDER BY s."salary" ASC, p."first_name" ASC, p."last_name" ASC, p."id" ASC +LIMIT 50; diff --git a/5.sql b/5.sql new file mode 100644 index 0000000..e69de29 diff --git a/6.sql b/6.sql new file mode 100644 index 0000000..e69de29 diff --git a/7.sql b/7.sql new file mode 100644 index 0000000..e69de29 diff --git a/8.sql b/8.sql new file mode 100644 index 0000000..e69de29 diff --git a/9.sql b/9.sql new file mode 100644 index 0000000..e69de29