-1

我基本上是在 mySQL 查询期间尝试使用 NOT IN 函数两次 我的新当前查询如下

SELECT `o`.`id`, `o`.`name`, `o`.`url`, `o`.`type`, `o`.`desc` FROM `offers` as `o` 
WHERE `o`.country_iso = '$country_iso' AND `o`.`id` not in 
(select distinct(offer_id) from conversions where ip = '$_SERVER[REMOTE_ADDR]' 
and converted != '0') AND `o`.`id` not in 
(select `offer_id` from `aff_disabled_offers` where `offer_id` = 'o.id' 
and `user_id` = '1') ORDER by rand() LIMIT $limit

该查询有效,但由于某种原因它完全忽略了这一点

AND `o`.`id` not in 
(select `offer_id` from `aff_disabled_offers` where `offer_id` = 'o.id') 
4

1 回答 1

1

您需要在条件之间指定一个运算符,例如 AND 或 OR。您还需要在 NOT IN 子句中进行有效查询。

SELECT `o`.`id`, `o`.`name`, `o`.`url`, `o`.`type`, `o`.`desc` 
FROM `offers` as `o` 
WHERE `o`.country_iso = '$country_iso' 
AND `o`.`id` not in (select distinct(offer_id)
                     from converstions where
                     from conversions 
                     where ip = '$_SERVER[REMOTE_ADDR]' 
                     and converted != '0')
AND `o`.`somevar` not in (select `somevar` from 
                          `sometable` where `offer_id` = 'o.id')
ORDER by rand() LIMIT 0,6
于 2013-01-12T00:41:09.027 回答