gpt4 book ai didi

mysql - SELECT SUM(1) FROM ( SELECT '0' as R FROM dual UNION ALL SELECT '1' as R FROM dual )

转载 作者:行者123 更新时间:2023-11-30 23:57:52 25 4
gpt4 key购买 nike

为什么下面的查询给出值 2 而不是我期望的 1

SELECT SUM(1) FROM (
SELECT '0' as R FROM dual
UNION
SELECT '1' as R FROM dual
)

但是这个查询满足预期?

SELECT SUM(R) FROM (
SELECT '0' as R FROM dual
UNION
SELECT '1' as R FROM dual
)

最佳答案

因为在第一个查询中,您对选择中的任何行的每次出现求和 1,而对于查询 1,您对选择中的每一行的“R”值求和。

关于mysql - SELECT SUM(1) FROM ( SELECT '0' as R FROM dual UNION ALL SELECT '1' as R FROM dual ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41241812/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com