Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CREATE VIEW NJITID _ Player _ History AS WITH player _ career AS ( SELECT playerID, COUNT ( DISTINCT yearID ) AS num _ years,

CREATE VIEW NJITID_Player_History AS
WITH player_career AS (
SELECT
playerID,
COUNT(DISTINCT yearID) AS num_years,
COUNT(DISTINCT teamID) AS num_teams,
SUM(HR) AS runs,
ROUND(SUM(H)/ NULLIF(SUM(AB),0),3) AS career_ba,
SUM(salary) AS tot_sal,
AVG(salary) AS avg_sal,
MIN(salary) AS min_Salary,
MAX(salary) AS max_salary,
ROUND((MAX(salary)- MIN(salary))/ NULLIF(MIN(salary),0),3) AS perct_incr,
COUNT(DISTINCT CASE WHEN lgID ='MLB' THEN yearID ELSE NULL END) AS max_appear,
MAX(CASE WHEN lgID ='MLB' THEN yearID ELSE NULL END) AS max_col
FROM
Batting
LEFT JOIN Salaries USING (playerID, yearID)
GROUP BY
playerID
), player_info AS (
SELECT
playerID,
nameGiven AS fullname,
SUM(401k) AS Total_401K,
MAX(CASE WHEN lgID ='MLB' THEN yearID ELSE NULL END) AS last_year_played
FROM
People
LEFT JOIN Fielding USING (playerID)
GROUP BY
playerID, fullname
), player_college AS (
SELECT
playerID,
COUNT(DISTINCT schoolID) AS Num_schools,
MAX(yearID) AS max_col
FROM
CollegePlaying
GROUP BY
playerID
), player_pitching AS (
SELECT
playerID,
SUM(W) AS tot_win,
SUM(SO) AS tot_so,
ROUND((SUM(SO)+ SUM(BB))/ NULLIF(SUM(IPouts)/3,0),3) AS car_pfr
FROM
Pitching
GROUP BY
playerID
), player_awards AS (
SELECT
playerID,
COUNT(*) AS tot_award_play
FROM
AwardsPlayer
GROUP BY
playerID
), manager_awards AS (
SELECT
playerID,
COUNT(*) AS tot_award_man
FROM
AwardsManager
GROUP BY
playerID
), hall_of_fame AS (
SELECT
playerID,
MAX(CASE WHEN inducted ='Y' THEN yearid ELSE NULL END) AS iyear,
COUNT(*) AS nomcount,
MAX(inducted) AS inducted
FROM
HallOfFame
GROUP BY
playerID
)
SELECT
player_info.playerID,
player_info.fullname,
player_info.Total_401K,
player_career.num_years,
player_career.num_teams,
player_career.runs,
player_career.career_ba,
player_career.tot_sal,
player_career.avg_sal,
player_career.min_Salary,
player_career.max_salary,
player_career.perct_incr,
player_college.Num_schools,
player_college.max_col,
player_career.last_year_played,
player_pitching.tot_win,
player_pitching.tot_so,
player_pitching.car_w,
player_pitching.car_l,
player_pitching.car_era,
player_pitching.car_whip,
player_pitching.car_so_per_nine

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Relational Database Design A Practical Approach

Authors: Marilyn Campbell

1st Edition

1587193175, 978-1587193170

More Books

Students also viewed these Databases questions

Question

The amount of work I am asked to do is reasonable.

Answered: 1 week ago

Question

The company encourages a balance between work and personal life.

Answered: 1 week ago