This commit is contained in:
8
1.sql
Normal file
8
1.sql
Normal file
@@ -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;
|
||||||
9
2.sql
Normal file
9
2.sql
Normal file
@@ -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;
|
||||||
15
3.sql
Normal file
15
3.sql
Normal file
@@ -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;
|
||||||
13
4.sql
Normal file
13
4.sql
Normal file
@@ -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;
|
||||||
9
5.sql
Normal file
9
5.sql
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
-- write a SQL query to find all teams that Satchel Paige played for.
|
||||||
|
-- Your query should return a table with a single column, one for the name of the teams.
|
||||||
|
SELECT DISTINCT t."name"
|
||||||
|
FROM "teams" AS t
|
||||||
|
JOIN "performances" AS perf
|
||||||
|
ON perf."team_id" = t."id"
|
||||||
|
JOIN "players" AS p
|
||||||
|
ON p."id" = perf."player_id"
|
||||||
|
WHERE p."first_name" = "Satchel" AND p."last_name" = "Paige";
|
||||||
14
6.sql
Normal file
14
6.sql
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
-- write a SQL query to return the top 5 teams, sorted by the total number of hits by players in 2001.
|
||||||
|
-- Call the column representing total hits by players in 2001 “total hits”.
|
||||||
|
-- Sort by total hits, highest to lowest.
|
||||||
|
-- Your query should return two columns, one for the teams’ names and one for their total hits in 2001.
|
||||||
|
SELECT
|
||||||
|
t."name",
|
||||||
|
SUM(perf."H") AS "total hits"
|
||||||
|
FROM "teams" AS t
|
||||||
|
JOIN "performances" AS perf
|
||||||
|
ON perf."team_id" = t."id"
|
||||||
|
WHERE perf."year" = '2001'
|
||||||
|
GROUP BY t."id", t."name"
|
||||||
|
ORDER BY "total hits" DESC
|
||||||
|
LIMIT 5;
|
||||||
Reference in New Issue
Block a user