From dc741d027318714af462eafd9cda0ba888eb10ff Mon Sep 17 00:00:00 2001 From: bot50 Date: Wed, 15 Apr 2026 09:01:56 +0000 Subject: [PATCH] daviddoji-cs50/problems/2024/sql/players@20260415T090156.245805757Z --- 1.sql | 2 ++ 10.sql | 5 +++++ 2.sql | 2 ++ 3.sql | 2 ++ 4.sql | 3 +++ 5.sql | 3 +++ 6.sql | 3 +++ 7.sql | 2 ++ 8.sql | 3 +++ 9.sql | 3 +++ 10 files changed, 28 insertions(+) create mode 100644 1.sql create mode 100644 10.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..c759e40 --- /dev/null +++ b/1.sql @@ -0,0 +1,2 @@ +-- write a SQL query to find the hometown (including city, state, and country) of Jackie Robinson. +SELECT "birth_city", "birth_state", "birth_country" FROM "players" WHERE "first_name" = "Jackie" AND "last_name" = "Robinson"; diff --git a/10.sql b/10.sql new file mode 100644 index 0000000..229dd67 --- /dev/null +++ b/10.sql @@ -0,0 +1,5 @@ +-- write SQL query to answer a question of your choice. This query should: + -- Make use of AS to rename a column + -- Involve at least condition, using WHERE + -- Sort by at least one column using ORDER BY +SELECT ROUND(AVG("weight"), 2) AS "Average Weight" FROM "players" WHERE "birth_year" > 2000 ORDER BY "first_name"; diff --git a/2.sql b/2.sql new file mode 100644 index 0000000..edfd0b7 --- /dev/null +++ b/2.sql @@ -0,0 +1,2 @@ +-- write a SQL query to find the side (e.g., right or left) Babe Ruth hit. +SELECT "bats" FROM "players" WHERE "first_name" = "Babe" AND "last_name" = "Ruth"; diff --git a/3.sql b/3.sql new file mode 100644 index 0000000..462576d --- /dev/null +++ b/3.sql @@ -0,0 +1,2 @@ +-- write a SQL query to find the ids of rows for which a value in the column debut is missing. +SELECT "id" FROM "players" WHERE "debut" IS NULL; diff --git a/4.sql b/4.sql new file mode 100644 index 0000000..90b1ea3 --- /dev/null +++ b/4.sql @@ -0,0 +1,3 @@ +-- write a SQL query to find the first and last names of players who were not born in the United States. +-- Sort the results alphabetically by first name, then by last name. +SELECT "first_name", "last_name" FROM "players" WHERE "birth_country" != "USA" ORDER BY "first_name" ASC, "last_name" ASC; diff --git a/5.sql b/5.sql new file mode 100644 index 0000000..1779604 --- /dev/null +++ b/5.sql @@ -0,0 +1,3 @@ +-- write a SQL query to return the first and last names of all right-handed batters. +-- Sort the results alphabetically by first name, then by last name. +SELECT "first_name", "last_name" FROM "players" WHERE "bats" = "R" ORDER BY "first_name" ASC, "last_name" ASC; diff --git a/6.sql b/6.sql new file mode 100644 index 0000000..dfe1cce --- /dev/null +++ b/6.sql @@ -0,0 +1,3 @@ +-- write a SQL query to return the first name, last name, and debut date of players born in Pittsburgh, Pennsylvania (PA). +-- Sort the results first by debut date—from most recent to oldest—then alphabetically by first name, followed by last name. +SELECT "first_name", "last_name", "debut" FROM "players" WHERE "birth_city" = "Pittsburgh" ORDER BY "debut" DESC, "first_name" ASC, "last_name" DESC; diff --git a/7.sql b/7.sql new file mode 100644 index 0000000..81c2f1b --- /dev/null +++ b/7.sql @@ -0,0 +1,2 @@ +-- write a SQL query to count the number of players who bat (or batted) right-handed and throw (or threw) left-handed, or vice versa. +SELECT COUNT(*) FROM "players" WHERE "bats" = "R" AND "throws" = "L" OR "bats" = "L" AND "throws" = "R"; diff --git a/8.sql b/8.sql new file mode 100644 index 0000000..53dc24b --- /dev/null +++ b/8.sql @@ -0,0 +1,3 @@ +-- write a SQL query to find the average height and weight, rounded to two decimal places, of baseball players who +-- debuted on or after January 1st, 2000. Return the columns with the name “Average Height” and “Average Weight”, respectively. +SELECT ROUND(AVG("height"), 2) AS "Average Height", ROUND(AVG("weight"), 2) AS "Average Weight" FROM "players" WHERE "debut" >= "2000-01-01"; diff --git a/9.sql b/9.sql new file mode 100644 index 0000000..02e11fa --- /dev/null +++ b/9.sql @@ -0,0 +1,3 @@ +-- write a SQL query to find the players who played their final game in the MLB in 2022. +-- Sort the results alphabetically by first name, then by last name. +SELECT "first_name", "last_name" FROM "players" WHERE "final_game" LIKE "2022%" ORDER BY "first_name" ASC, "last_name" ASC;