简体   繁体   English

合并两个查询的字段

[英]Combining fields from two queries

Here are the two tables I'm working with: 这是我正在使用的两个表:

NBAGameLog: NBAGameLog:

Player_ID, Team, Minutes, Date_Played

Players: 玩家:

Player_ID, First Name, Last Name, Position

I have these two queries right now: 我现在有两个查询:

AvgMP15: 平均MP15:

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: 平均MP:

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;

The first one gives me a player's name, position, team and his average minutes played from the last 15 games. 第一个给我一个球员的名字,位置,球队以及他最近15场比赛的平均上场时间。

The second one gives me his averave minutes played for the entire season. 第二节给了我他整个赛季的平均上场时间。

I want to compare these two, so I'd like a query that pulls: 我想比较这两个,所以我想查询一个拉:

First Name, Last Name, Position, Team, Minutes Played in the Last 15, Minutes played the whole season, Difference between 15 and season. 名,姓,名,位置,球队,过去15分钟打的分钟数,整个赛季打的分钟数,第15和赛季之间的差额。

Is this possible? 这可能吗?

I figured it out! 我想到了!

Here's the query: 这是查询:

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;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM