3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
6 # May you do good and not evil.
7 # May you find forgiveness for yourself and forgive others.
8 # May you share freely, never taking more than you give.
10 #***********************************************************************
12 # Test for queries of the form:
14 # SELECT p, max(q) FROM t1;
16 # Demonstration that the value returned for p is on the same row as
20 set testdir [file dirname $argv0]
21 source $testdir/tester.tcl
31 SELECT p, max(q) FROM t1;
36 SELECT p, min(q) FROM t1;
41 INSERT INTO t1 VALUES(1,2);
42 SELECT p, max(q) FROM t1;
47 SELECT p, min(q) FROM t1;
52 INSERT INTO t1 VALUES(3,4);
53 SELECT p, max(q) FROM t1;
58 SELECT p, min(q) FROM t1;
59 SELECT p FROM (SELECT p, min(q) FROM t1);
64 INSERT INTO t1 VALUES(5,0);
65 SELECT p, max(q) FROM t1;
66 SELECT p FROM (SELECT max(q), p FROM t1);
71 SELECT p, min(q) FROM t1;
76 INSERT INTO t1 VALUES(6,1);
77 SELECT p, max(q) FROM t1;
78 SELECT p FROM (SELECT max(q), p FROM t1);
81 do_test minmax4-1.10 {
83 SELECT p, min(q) FROM t1;
86 do_test minmax4-1.11 {
88 INSERT INTO t1 VALUES(7,NULL);
89 SELECT p, max(q) FROM t1;
92 do_test minmax4-1.12 {
94 SELECT p, min(q) FROM t1;
97 do_test minmax4-1.13 {
99 DELETE FROM t1 WHERE q IS NOT NULL;
100 SELECT p, max(q) FROM t1;
103 do_test minmax4-1.14 {
105 SELECT p, min(q) FROM t1;
109 do_test minmax4-2.1 {
111 CREATE TABLE t2(a,b,c);
112 INSERT INTO t2 VALUES
117 SELECT a, max(b), c FROM t2 GROUP BY a ORDER BY a;
120 do_test minmax4-2.2 {
122 SELECT a, min(b), c FROM t2 GROUP BY a ORDER BY a;
125 do_test minmax4-2.3 {
127 SELECT a, min(b), avg(b), count(b), c FROM t2 GROUP BY a ORDER BY a DESC;
129 } {2 3 3.0 1 5 1 1 1.5 2 4}
130 do_test minmax4-2.4 {
132 SELECT a, min(b), max(b), c FROM t2 GROUP BY a ORDER BY a;
135 do_test minmax4-2.5 {
137 SELECT a, max(b), min(b), c FROM t2 GROUP BY a ORDER BY a;
140 do_test minmax4-2.6 {
142 SELECT a, max(b), b, max(c), c FROM t2 GROUP BY a ORDER BY a;
144 } {1 2 1 4 4 2 3 3 5 5}
145 do_test minmax4-2.7 {
147 SELECT a, min(b), b, min(c), c FROM t2 GROUP BY a ORDER BY a;
149 } {1 1 {} 2 2 2 3 3 5 5}