嘿,我怎样才能将下面的两个查询合并为一个?所以我得到的结果集是因为第一个查询是从表中得到点结果,而下面的表是从另一个表得到我需要的其余部分,但是两者都相互关联,因为第一个查询被执行时可能是使用它进行secound查询。我只是不知道怎么样?任何帮助都很棒。
SELECT t.team_id, t.teamname, t.code, t.value,
SUM(Case When track_id = (SELECT MAX(track_id) FROM team_stats) Then points Else 0 End) lastracepoints,
SUM(points) AS points
FROM team_stats ts
Left Join teams t
on t.team_id = ts.team_id
GROUP BY ts.team_id
SELECT SUM(IF(qual_pos = '1', 1,0)) AS poles,
SUM(IF(race_pos <= '3', 1,0)) AS podiums,
SUM(IF(race_pos = '1', 1,0)) AS victories,
SUM(overtakes) AS overtakes
FROM driver_stats s
left join drivers d
on d.drivers_id = s.drivers_id
GROUP by d.team_id