以下是我正在使用的两个表:
NBAGameLog:
Player_ID, Team, Minutes, Date_Played
玩家:
Player_ID, First Name, Last Name, Position
我现在有这两个问题:
AvgMP15:
SELECT DISTINCTROW Players.FirstName, Players.LastName, Players.Position, NBAGameLog.Tm, ROUND(AVG(AvgMP1),2) AS AvgMP
FROM (SELECT Players.FirstName, Players.LastName, Players.Position, NBAGameLog.Tm, ROUND(AVG(NBAGameLog.MP),2) As AvgMP1
FROM NBAGameLog INNER JOIN Players ON NBAGameLog.Player_ID = Players.Player_ID
WHERE (((NBAGameLog.Date_Played) Between Date()-15 And Date()))
GROUP BY NBAGameLog.Date_Played, Players.Position, NBAGameLog.FD_Points, Players.FirstName, Players.LastName, NBAGameLog.Tm, Players.Player_ID) AS [%$##@_Alias]
GROUP BY Players.FirstName, Players.LastName, Players.Position, NBAGameLog.Tm;
AvgMP:
SELECT DISTINCTROW p.FirstName, p.LastName, gl.Tm, ROUND(Avg(gl.MP),2) AS AvgMPS
FROM NBAGameLog AS gl INNER JOIN Players AS p ON gl.Player_ID = p.Player_ID
GROUP BY p.FirstName, p.LastName, gl.Tm
ORDER BY Avg(gl.MP) DESC;
第一个给我一个球员的名字,位置,球队和他在过去15场比赛中的平均上场时间。
第二个给了我他整个赛季的平均上场时间。
我想比较这两个,所以我想要一个提取的查询:
名字,姓氏,位置,球队,分钟在过去的15场比赛中出场,整个赛季的分钟比赛,15场和赛季之间的差距。
这可能吗?
答案 0 :(得分:0)
我明白了!
以下是查询:
SELECT DISTINCTROW p.FirstName, p.LastName, gl.Tm, ROUND(Avg(gl.MP),2) AS Season, ROUND(Avg(gl2.MP),2) AS Last15, ROUND((Last15-Season),2) AS Diff
FROM (NBAGameLog AS gl INNER JOIN Players AS p ON gl.Player_ID = p.Player_ID) INNER JOIN NBAGameLog AS gl2 ON gl2.Player_ID = gl.Player_ID
WHERE gl2.Date_Played Between Date()-15 And Date()
GROUP BY p.FirstName, p.LastName, gl.Tm
ORDER BY p.LastName;