Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Aggregation function for sqlite

Execute below script for create test table.

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

Now, table is created, and it is empty table.

Execute below script,

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

It will return below result(one row).

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

Execute below script,

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

It will return below result(no result).

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

Is there somebody explain the reason?

like image 495
boiledwater Avatar asked Sep 21 '26 13:09

boiledwater


1 Answers

The documentation says:

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.

In your first query, there is one group which does not have any records.

In your second query, there is no group.

like image 86
CL. Avatar answered Sep 24 '26 03:09

CL.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!