与多个AND谓词混淆

时间:2019-04-25 18:38:40

标签: mysql sql

SELECT *
FROM TABLE
WHERE classi_type = '3'
  AND job_role IN (52)
  AND job_qualification IN (25)
  AND job_type IN (7)
  AND job_gender = 'Female'
  AND (job_expmin >= '5'
       AND job_expmax <= '10')
  OR (job_salmin >= '0'
      AND job_salmax <= '30000')
  OR (job_agemin >= '24'
      AND job_agemax <= '33')

IN条件正常。问题出在多个AND上。

2 个答案:

答案 0 :(得分:1)

我认为您只需要正确的括号即可

Select *
from table 
where classi_type = '3' AND
      job_role IN (52) AND
      job_qualification IN (25) AND
      job_type IN (7) AND
      job_gender = 'Female' AND
      ((job_expmin >= 5 AND job_expmax <= 10) OR
       (job_salmin >= 0 AND job_salmax <= 30000) OR
       (job_agemin >= 24 AND job_agemax <= 33)
     )

我猜最后引用的六列实际上是某种数字。比较应该是数字,而不是字符串。

答案 1 :(得分:0)

我认为您需要这个:

SELECT *
FROM TABLE
WHERE classi_type = '3'
  AND job_role IN (52)
  AND job_qualification IN (25)
  AND job_type IN (7)
  AND job_gender = 'Female'
  AND job_expmin >= '5'
  AND job_expmax <= '10'
  AND job_salmin >= '0'
  AND job_salmax <= '30000'
  AND job_agemin >= '24'
  AND job_agemax <= '33'