Using Oracle SQL, I'm trying to write a statement that answers the following question: NFL Teams with more wins than their division average that also have more penalty yards than the division average.
I have two separate statements that are able to return each individually (IE: a table that lists teams with more wins than division average, and a separate table that lists teams with more penalty yards than average)
I am running into errors when I try and intersect the two queries however. 'Missing select keyword' is the given error.
WITH divisionPenaltyYards AS
(
SELECT division
,avg(penaltyyards) AS AVGPenalty
FROM nfl.teams
GROUP BY division
)
WITH divisionWins AS
(
SELECT division
,avg(wins) AS AVGWins
FROM nfl.teams
GROUP BY division
)
SELECT team
FROM nfl.teams
INNER JOIN divisionPenaltyYards
ON nfl.teams.division = divisionPenaltyYards.division
WHERE penaltyyards > AVGPenalty
INTERSECT
SELECT team
FROM nfl.teams
INNER JOIN divisionWins
ON nfl.teams.division = divisionWins.division
WHERE wins > AVGWins;
EDIT: More info per request
NFL.Teams consists of stats for all the teams in the NFL. Team, division, wins, penaltyyards...
An example of the data set would include
Packers, NFC NORTH, 6, 984
Steelers, AFC NORTH, 12, 817
and so on.
Desired result would be a table listing all teams that have more wins than the division average, while also having more penalty yards than the division average.