使用或在一条语句中进行多组查询

iswrvxsc  于 2021-06-18  发布在  Mysql
关注(0)|答案(1)|浏览(276)

我试图找出低“分数”添加到其他分数高的表格中。简单地说,我想知道谁的一个问题得了1分,而其他问题得了2分或以上。我想到了这个;

SELECT * FROM `review_survey`, `users` WHERE review_survey.user_id =users.kituser_id AND 
(review_survey.s1 < 2 AND review_survey.s2 >= 2 AND review_survey.s3 >= 2 ) 
OR (safeguard_review_survey.s1 >= 2 AND safeguard_review_survey.s2 < 2 
AND safeguard_review_survey.s3 >= 2) AND `complete` = 1 AND users.account = 1

但它返回的是一个不可能精确的海量数据集。
我从哪里开始?

t5zmwmid

t5zmwmid1#

首先,请尝试以下步骤:

SELECT * FROM 
    `review_survey`, `users` 
WHERE 
     review_survey.user_id =users.kituser_id 
AND (  --<-- missing parenthesis
      (review_survey.s1 < 2 AND review_survey.s2 >= 2 AND review_survey.s3 >= 2 ) 
      OR 
      (safeguard_review_survey.s1 >= 2 AND safeguard_review_survey.s2 < 2 AND safeguard_review_survey.s3 >= 2)
    )   --<-- missing parenthesis
AND `complete` = 1 AND users.account = 1

更好的办法是,把东西搬来搬去

condition AND condition2 AND condition3 AND ( condition4 OR condition5)

到目前为止,它很有可能和或不工作,如你所料

相关问题