基本上,我的 0 OR 0 返回 1 - 这不是我真正想要的 :) 我不太确定为什么,因为如果我选择 0 OR 0 我得到 0..
我认为这可能是因为 is_premium_dealer 是 enum('0','1') 而不是 bool (不要问我为什么,我没有设计这个数据库!)
有谁知道这是否是因为 ENUM,如果是,我将如何将其转换为整数?
提前致谢!约翰。
SELECT is_premium_dealer, company_name,
(SELECT COUNT(*) FROM adverts WHERE user_id = users.id AND is_archived = 0) AS innerquery,
((SELECT COUNT(*) FROM adverts WHERE user_id = users.id AND is_archived = 0 AND is_deleted = 0) > 0 OR is_premium_dealer = 1) AS logicissue
FROM `user_profiles_dealers`
LEFT JOIN `users` ON user_profiles_dealers.user_id = users.id
LEFT JOIN `counties` ON user_profiles_dealers.county_id = counties.id
LEFT JOIN `countries` ON user_profiles_dealers.country_id = countries.id
WHERE (users.is_active=1)
AND (((SELECT COUNT(*) FROM adverts WHERE user_id = users.id AND is_archived = 0 AND is_deleted = 0) > 0) OR is_premium_dealer > 0)
AND company_name like '%autocraft%' limit 5\G
结果:
*************************** 1. row ***************************
is_premium_dealer: 0
company_name: A Company
innerquery: 0
logicissue: 1
1 row in set (0.00 sec)