Mysql:不能使用子查询字段作为条件吗?

时间:2012-08-28 09:04:50

标签: mysql

此代码运行正常。特别注意'AS commercial'子查询字段。它有效。

SELECT `Contacts`.`id`,
    (
        SELECT `team_members`.`id`
        FROM team_members
        INNER JOIN team_categories_team_members AS memcat
            ON `team_members`.`id` = `memcat`.`team_member_id`
        WHERE `memcat`.`team_category_id` =3
    ) AS commercial
    FROM `oys001`.`team_members` AS `Contacts`
    JOIN `oys001`.`brands_team_members` AS `BrandsTeamMember` ON ( 
        `BrandsTeamMember`.`brand_id` =2
        AND `BrandsTeamMember`.`team_member_id` = `Contacts`.`id` )

但是,现在我想对它执行一个条件,所以我只想添加:

 WHERE commercial > 0

它告诉我这个领域不存在......这里出了什么问题?

1 个答案:

答案 0 :(得分:0)

用括号括起您的初始查询