简体   繁体   English

为什么这些查询产生不同的结果?

[英]why do these queries produce different results?

I have run these two queries that look like they do the same thing, but give different results: 我已经运行了这两个看起来像他们做同样事情的查询,但给出了不同的结果:

SELECT COUNT(stage1) AS total 
FROM progress_status 
WHERE stage1 = 3 
AND stage2 != 3 AND stage3 !=3 AND stage4 !=3 AND stage5 !=3;

# total = 90

SELECT COUNT(stage1) AS total 
FROM progress_status 
WHERE stage1 = 3 
AND (stage2,stage3,stage4,stage5) != (3,3,3,3)

# total = 314

第二个是:

AND (stage2 != 3 OR stage3 !=3 OR stage4 !=3 OR stage5 !=3);

It's normal: 这是正常的:

  • Your first query asks all stage columns to be different from 3 您的第一个查询要求所有阶段列与3不同
  • Your second query asks those columns not beeing equal to 3 at the same time, so if one is different from 3 record is taken! 你的第二个查询要求那些同时不等于3的列,所以如果一个不同于3个记录就被采取! This query is like you're using OR in your WHERE clause. 此查询就像您在WHERE子句中使用OR一样。

(stage2,stage3,stage4,stage5) != (3,3,3,3)stage2 != 3 OR stage3 !=3 OR stage4 !=3 OR stage5 !=3

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM