2012-08-28 66 views
0

此代碼運行正常。特別關注'AS商業'子查詢領域。有用。Mysql:不能使用子查詢字段作爲條件嗎?

 
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

它不是一個真正的領域,這是一個已經別名計算值。使用關鍵字'HAVING' - 'HAVING commercial> 0',而不是使用'WHERE'。 –

回答

0

環繞你inital查詢括號

SELECT * 
FROM (yourqueryhere) AS `v` 
WHERE commercial > 0