Hello,
This is my first post, I am a SQL NEWB, and I am in need of some help. I think I have managed well but I have struggled with this, “Off Platform Project: The Best of Baseball Awards”, project. Here is what I did, please let me know what you think.
Attempt at Heaviest Hitters
SELECT batting.yearid, teams.name, AVG(weight)
FROM batting
LEFT JOIN people ON batting.playerid = people.playerid
LEFT JOIN teams ON teams.teamid = batting.teamid
GROUP BY batting.yearid, teams.name
ORDER BY yearid ASC
limit 10;
Attempt at Shortest Sluggers
SELECT batting.yearid, teams.name, ROUND(AVG(height), 2)
FROM batting
LEFT JOIN people ON batting.playerid = people.playerid
LEFT JOIN teams ON teams.teamid = batting.teamid
GROUP BY batting.yearid, teams.name
ORDER BY 3 ASC
LIMIT 10;
Attempt at Biggest Spenders
SELECT salaries.yearid, teams.name, SUM(salary)
FROM salaries
JOIN teams ON salaries.teamid = teams.teamid
GROUP BY salaries.yearid, teams.name
ORDER BY 3 DESC;
Attempt at Cost Per Win
SELECT salaries.yearid, teams.name, ROUND(SUM(salary) / teams.w) AS “CPW”, teams.w
FROM salaries
JOIN teams ON salaries.teamid = teams.teamid
WHERE salaries.yearid = 2010
GROUP BY salaries.yearid, teams.name, teams.w
ORDER BY 3 ASC;
Attempt at Priciest Starter (w/o people and this seems to work)
SELECT pitching.playerid, pitching.gs, ROUND(SUM(salaries.salary) / pitching.gs) AS “Cost”
FROM pitching
JOIN salaries ON pitching.playerid = salaries.playerid
WHERE gs >= 10
GROUP BY pitching.playerid, pitching.gs
ORDER BY 3 DESC;
Attempt at Priciest Starter (w/ people but its a fail and I don’t know why)
SELECT
people.namegiven,
pitching.playerid,
pitching.gs,
ROUND(SUM(salaries.salary) / pitching.gs) AS “Cost”
FROM pitching
JOIN salaries ON pitching.playerid = salaries.playerid
JOIN people ON salaries.playerid = people.namegiven
WHERE gs >= 10
GROUP BY people.namegiven, pitching.playerid, pitching.gs
ORDER BY 3 DESC;
Thanks for looking this over.
Best,
Curt