1
SELECT * 
FROM domains
WHERE domains_id IN
      (
        SELECT domains_subscriptions_domain
        FROM domains_subscriptions
        WHERE domains_subscriptions_selmgec='$_SESSION[selmgec]'
      )
AND domains_id NOT IN
      (
        SELECT domains_block_domain
        FROM domains_block
        WHERE domains_block_selmgec='$_SESSION[selmgec]'
          AND domains_block_member='$_SESSION[member]'
      )
ORDER BY RAND()

我想获取域中的所有域,这些域也在域订阅中,但它们不在域块中。这适用于上面的查询。但后来我希望能够添加

AND domains_id NOT IN
      (
         SELECT domains_hits_domain 
         FROM domains_hits
         WHERE domains_hits_selmgec='$_SESSION[selmgec]'
            AND domains_hits_member='$_SESSION[member]'
      )

这对查询,所以它也过滤掉域中的域是什么域,但它目前给了我所有域,因为我认为它只会过滤掉域块和域中的域,但我想要它要么是!

任何帮助深表感谢

4

1 回答 1

1

尝试这个:

SELECT * 
FROM domains
WHERE domains_id IN
      (
        SELECT domains_subscriptions_domain
        FROM domains_subscriptions
        WHERE domains_subscriptions_selmgec='$_SESSION[selmgec]'
      )
AND domains_id NOT IN
      (
        SELECT domains_block_domain
        FROM domains_block
        WHERE domains_block_selmgec='$_SESSION[selmgec]'
          AND domains_block_member='$_SESSION[member]'
        UNION ALL
        SELECT domains_hits_domain 
        FROM domains_hits
        WHERE domains_hits_selmgec='$_SESSION[selmgec]'
           AND domains_hits_member='$_SESSION[member]'
      )
ORDER BY RAND()

或者

SELECT * 
FROM domains
WHERE domains_id IN
      (
        SELECT domains_subscriptions_domain
        FROM domains_subscriptions
        WHERE domains_subscriptions_selmgec='$_SESSION[selmgec]'
      )
AND NOT (
      domains_id IN
      (
        SELECT domains_block_domain
        FROM domains_block
        WHERE domains_block_selmgec='$_SESSION[selmgec]'
          AND domains_block_member='$_SESSION[member]'
      )
      OR
      domains_id IN
      ( 
        SELECT domains_hits_domain 
        FROM domains_hits
        WHERE domains_hits_selmgec='$_SESSION[selmgec]'
           AND domains_hits_member='$_SESSION[member]'
      )
    )
ORDER BY RAND()
于 2013-01-20T10:42:45.207 回答