为什么在sqlite中,`select s select(选择1联合选择2联合选择3)相交3联合3联合选择4“等于4,而不是3?
在sqlite中,如果我输入:
SELECT (SELECT 1 UNION SELECT 2 UNION SELECT 3) INTERSECT SELECT 3 UNION SELECT 4
我得到结果4
。怎么可能?
选择1联合选择2选择3
是(1,2,3)
,对吗? 选择3联合选择4
是(3,4)
。因此,相交应该为3
,对吗?我出了什么问题?
编辑:说相互评估
首先评估我的问题,因为((1,2,3)Intersect(3))Union(4)
is (3,4)
,而不是4
。
In SQLite, if I type:
SELECT (SELECT 1 UNION SELECT 2 UNION SELECT 3) INTERSECT SELECT 3 UNION SELECT 4
I get the result 4
. How is that possible?
SELECT 1 UNION SELECT 2 SELECT 3
is (1, 2, 3)
, right? And SELECT 3 UNION SELECT 4
is (3, 4)
. So, the intersect should be 3
, right? What am I getting wrong?
EDIT: Saying that INTERSECT
is evaluated first does not answer my question, as ((1,2,3) INTERSECT (3)) UNION (4)
is (3,4)
, rather than 4
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您以这样的方式编写语句:
您可以看到您将3
选择
语句与操作员Union
和Intersect
。所有3个语句都应返回相同数量的列。
您的第一个语句:
实际上仅返回1行带1列,,,
因此,您的代码等同于:
Intersect
,最后Union
返回4
。您打算写:
如果 结果将是
(3,4)
。If you write your statement like this:
you can see that you are combining 3
SELECT
statements with the operatorsUNION
andINTERSECT
.All 3 statements should return the same number of columns.
Your 1st statement:
actually returns only 1 row with 1 column, try it, which is the 1st row and the result is
1
.So your code is equivalent to:
which returns nothing for
INTERSECT
and finallyUNION
returns4
.If you meant to write:
then the result would be
(3, 4)
.