3

在将一个表过滤为每个用户的最新条目后,我正在尝试加入三个表。但是,突然间我遇到了错误Duplicate column name 'username'。我需要加入这个“重复”专栏。我该如何解决?

SELECT customers.id,customers.name,customers.username,customers.phone,customers.email,radcheck.value as password
    FROM customers
    RIGHT JOIN radcheck ON customers.username = radcheck.username
    LEFT JOIN (
            SELECT * FROM radacct INNER JOIN (
                SELECT username,MAX(acctupdatetime) AS latest FROM radacct GROUP BY username
            ) as radrecent 
            ON radacct.username = radrecent.username 
            AND radacct.acctupdatetime = radrecent.latest
    ) as radlatest 
        ON customers.username = radlatest.username
    WHERE radcheck.attribute = 'Cleartext-Password'
4

1 回答 1

3

*您有两列是username. 您需要满足其中一项或两项的资格。下面的例子:

SELECT 
   customers.id,customers.name,customers.username,customers.phone,customers.email,radcheck.value as password
        FROM customers
        RIGHT JOIN radcheck ON customers.username = radcheck.username
        LEFT JOIN (
                SELECT radrecent.username, latest FROM radacct INNER JOIN (
                     --^^^^^^^^^
                    SELECT username,MAX(acctupdatetime) AS latest FROM radacct GROUP BY username
                ) as radrecent 
                ON radacct.username = radrecent.username 
                AND radacct.acctupdatetime = radrecent.latest
        ) as radlatest 
            ON customers.username = radlatest.username
        WHERE radcheck.attribute = 'Cleartext-Password'
于 2017-03-23T23:15:35.837 回答