尝试使用子查询中的连接表的位置执行语句时出错

时间:2013-05-14 18:35:22

标签: mysql

我正试图从我的桌子上获得花费数小时的时间。有用。但现在我想将其限制为一个用户组。所以我这样做了:

SELECT
    s.shortname AS servername, s.displaycolor AS displaycolor,
    MIN(
        if(`yearweek`=yearweek(CURRENT_DATE(),3) AND (s.admin_group=u.usergroupid OR find_in_set(s.admin_group, u.membergroupids)>0),
            (SELECT COUNT(*)
            FROM godziny_tygodnie AS x
                LEFT JOIN vbulletin.vb_user AS xu ON xu.userid=x.dbid
            WHERE gw.sid=x.sid
            AND x.`yearweek`=gw.`yearweek` AND x.`time` > gw.`time`)+1
            AND ( xu.usergroupid=s.admin_group OR find_in_set(s.admin_group, xu.membergroupids)>0)
        , NULL)
    ) AS rweek0,
    -- there are more columns simillar to previous, but with different time interval
FROM godziny_tygodnie gw
    INNER JOIN godziny_miesiace gm ON gw.dbid=gm.dbid AND gw.sid=gm.sid
    INNER JOIN godziny_lacznie gt ON gw.dbid=gt.dbid AND gw.sid=gt.sid
    LEFT JOIN serwery AS s ON s.id=gw.sid
    LEFT JOIN vbulletin.vb_user u ON u.userid=gw.dbid
WHERE gw.dbid=:uid
GROUP BY gw.dbid, gw.sid

它给了我错误Column not found: 1054 Unknown column 'xu.usergroupid' in 'field list'

为什么不能执行? vbulletin.vb_user.usergroupid存在...

1 个答案:

答案 0 :(得分:0)

问题是错误的括号。从9.行末尾的)+1应该在10行的末尾。现在一切正常:)