1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-30 19:03:16 +03:00

When doing a DISTINCT aggregate that contains an ORDER BY, only the

arguments to the aggregate need to be distinct, not the ORDER BY terms.

FossilOrigin-Name: d2dbbdf7194bab4e5e3b74d3dbffb012a335829824c775c72dd7347c013d2125
This commit is contained in:
drh
2023-10-25 14:54:16 +00:00
parent a9a7d118f6
commit 8f99cb9ad6
5 changed files with 34 additions and 12 deletions

View File

@ -102,4 +102,21 @@ do_execsql_test aggorderby-7.1 {
json_group_array(x ORDER BY y NULLS LAST, x) FROM c;
} {[2,4,5,3,1] [5,3,1,2,4]}
# The DISTINCT only applies to the function arguments, not to the
# ORDER BY arguments.
#
do_execsql_test aggorderby-8.0 {
WITH c(x,y,z) AS (VALUES('a',4,5),('b',3,6),('c',2,7),('c',1,8))
SELECT group_concat(DISTINCT x ORDER BY y, z) FROM c;
} {c,b,a}
do_execsql_test aggorderby-8.1 {
WITH c(x,y,z) AS (VALUES('a',4,5),('b',3,6),('b',2,7),('c',1,8))
SELECT group_concat(DISTINCT x ORDER BY y, z) FROM c;
} {c,b,a}
do_execsql_test aggorderby-8.2 {
WITH c(x,y) AS (VALUES(1,1),(2,2),(3,3),(3,4),(3,5),(3,6))
SELECT sum(DISTINCT x ORDER BY y) FROM c;
} 6
finish_test