多个JOIN太复杂了

时间:2016-09-18 19:11:16

标签: mysql

这比我可以遵循的要复杂得多。我已在此处的其他帖子中修改了此查询,现在我需要添加另一个联接,但它无效。

以下是MySQL中的当前查询:

SELECT * FROM (SELECT *,
                @rn := IF(@prev = class, @rn + 1, 1) AS rn,
                @prev := class
               FROM HeatWaveData
               JOIN
                (SELECT @prev := NULL, @rn := 0) AS vars
                ORDER BY class, score DESC)
               AS T1
               WHERE rn <= 3
                 AND score > 0
                 AND dsqreason = ''
                 AND class <> ''

现在我需要JOIN (SELECT * FROM Awards WHERE active ON Awards.award = HeatWaveData.award) 但它失败了。我尝试过多次改变和不同的事情,但不断出错。

这是我更新的查询和错误:

SELECT * FROM (SELECT *,
                @rn := IF(@prev = class, @rn + 1, 1) AS rn,
                @prev := class
               FROM HeatWaveData
               JOIN
                (SELECT @prev := NULL, @rn := 0) AS vars
                ORDER BY class, score DESC)
               AS T1
             LEFT JOIN
               (SELECT * FROM Awards WHERE active = '1'
                ON Awards.award = T1.award) AS T2
             WHERE rn <= 3
                 AND score > 0
                 AND dsqreason = ''
                 AND class <> ''

错误:

error: #1064 - You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near
'ON Awards.award = T1.award) AS T2 WHERE rn <= 3 AN' at line 11 

1 个答案:

答案 0 :(得分:2)

尝试使用&#34;普通&#34;替换您的子选择。加入:

<强>旧

a.h

LEFT JOIN
(SELECT * FROM Awards WHERE active = '1'
ON Awards.award = T1.award) AS T2