gpt4 book ai didi

sql - sqlite的聚合函数

转载 作者:行者123 更新时间:2023-12-03 17:04:12 25 4
gpt4 key购买 nike

执行以下脚本以创建测试表。

create table if not exists t1 (id1 int,id2 int);

现在表已经创建好了,而且是空表。

执行下面的脚本,

select max(id1), max(id2) from t1

它将返回以下结果(一行)。

max(id1)      max(id2)
----------- --------
<null> <null>

执行下面的脚本,

select max(id1), max(id2) from t1 group by id1,id2

它将返回以下结果(无结果)。

max(id1)      max(id2)
----------- --------

有没有人解释一下原因?

最佳答案

documentation说:

The max() aggregate function returns the maximum value of all values in the group. [...] Aggregate max() returns NULL if and only if there are no non-NULL values in the group.

在您的第一个查询中,有一个组没有任何记录。

在您的第二个查询中,没有组。

关于sql - sqlite的聚合函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13173445/

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