这是我们当前的查询:
SELECT info.yearID, info.nameFirst, info.nameLast, info.HR
FROM (
SELECT a.yearID, a.nameFirst, a.nameLast, a.HR FROM (
SELECT @curRank := @curRank+1 as rank, i.nameFirst, i.nameLast, i.masterID, i.HR, i.yearID
FROM ( SELECT (select @curRank := 0), m.nameFirst, b.yearID, m.nameLast, b.masterId, sum(b.HR) as HR
FROM master as m left join batting as b on b.masterID = m.masterID
WHERE b.yearID = 1882 group by b.masterID)
as i ORDER BY i.HR desc
)a
WHERE a.HR = (SELECT i.HR
FROM (
SELECT (select @curRank := 0), m.nameFirst, b.yearID, m.nameLast, b.masterId, sum(b.HR) as HR
FROM master as m left join batting as b on b.masterID = m.masterID
WHERE b.yearID = 1882
group by b.masterID
)
as i ORDER BY i.HR desc limit 1)) as info ;
我们需要做到这一点,以便1882年不是硬编码,而是从1871年到2013年。
我不是在寻找答案,只是朝着正确的方向前进。
答案 0 :(得分:0)
b.yearID = @yearVar
^^将解析@符号以及您对@curRank的处理方式将类似。它是提供某种动态价值的一种手段。
答案 1 :(得分:0)
只需将其更改为:
WHERE b.yearID BETWEEN 1871 AND 2013