dependencies.
David Hartwig
-QUERY: SELECT d1, count(*) FROM DATETIME_TBL
- GROUP BY d1 HAVING count(*) > 1;
-d1 |count
-----------------------------+-----
-Thu Jun 13 00:00:00 1957 PDT| 2
-Mon Feb 10 09:32:01 1997 PST| 3
-Mon Feb 10 17:32:01 1997 PST| 13
-Sun Feb 16 17:32:01 1997 PST| 2
-Sat Mar 01 17:32:01 1997 PST| 2
-invalid | 2
-(6 rows)
+QUERY: CREATE TABLE test_having (a int, b int, c char(8), d char);
+QUERY: INSERT INTO test_having VALUES (0, 1, 'XXXX', 'A');
+QUERY: INSERT INTO test_having VALUES (1, 2, 'AAAA', 'b');
+QUERY: INSERT INTO test_having VALUES (2, 2, 'AAAA', 'c');
+QUERY: INSERT INTO test_having VALUES (3, 3, 'BBBB', 'D');
+QUERY: INSERT INTO test_having VALUES (4, 3, 'BBBB', 'e');
+QUERY: INSERT INTO test_having VALUES (5, 3, 'bbbb', 'F');
+QUERY: INSERT INTO test_having VALUES (6, 4, 'cccc', 'g');
+QUERY: INSERT INTO test_having VALUES (7, 4, 'cccc', 'h');
+QUERY: INSERT INTO test_having VALUES (8, 4, 'CCCC', 'I');
+QUERY: INSERT INTO test_having VALUES (9, 4, 'CCCC', 'j');
+QUERY: SELECT max(a) FROM test_having
+ GROUP BY lower(c) HAVING count(*) > 2 OR min(b) = 3;
+max
+---
+ 5
+ 9
+(2 rows)
+QUERY: SELECT lower(c), count(c) FROM test_having
+ GROUP BY lower(c) HAVING count(*) > 2 OR min(a) = max(a);
+lower |count
+--------+-----
+bbbb | 3
+cccc | 4
+xxxx | 1
+(3 rows)
+
+QUERY: SELECT c, max(a) FROM test_having
+ GROUP BY c HAVING count(*) > 2 OR min(a) = max(a);
+c |max
+--------+---
+XXXX | 0
+bbbb | 5
+(2 rows)
+
+QUERY: DROP TABLE test_having;
-QUERY: CREATE TABLE test_missing_target (a int, b int, c char(8));
-QUERY: INSERT INTO test_missing_target VALUES (0, 1, 'XXXX');
-QUERY: INSERT INTO test_missing_target VALUES (1, 2, 'AAAA');
-QUERY: INSERT INTO test_missing_target VALUES (2, 2, 'AAAA');
-QUERY: INSERT INTO test_missing_target VALUES (3, 3, 'BBBB');
-QUERY: INSERT INTO test_missing_target VALUES (4, 3, 'BBBB');
-QUERY: INSERT INTO test_missing_target VALUES (5, 3, 'bbbb');
-QUERY: INSERT INTO test_missing_target VALUES (6, 4, 'cccc');
-QUERY: INSERT INTO test_missing_target VALUES (7, 4, 'cccc');
-QUERY: INSERT INTO test_missing_target VALUES (8, 4, 'CCCC');
-QUERY: INSERT INTO test_missing_target VALUES (9, 4, 'CCCC');
+QUERY: CREATE TABLE test_missing_target (a int, b int, c char(8), d char);
+QUERY: INSERT INTO test_missing_target VALUES (0, 1, 'XXXX', 'A');
+QUERY: INSERT INTO test_missing_target VALUES (1, 2, 'AAAA', 'b');
+QUERY: INSERT INTO test_missing_target VALUES (2, 2, 'AAAA', 'c');
+QUERY: INSERT INTO test_missing_target VALUES (3, 3, 'BBBB', 'D');
+QUERY: INSERT INTO test_missing_target VALUES (4, 3, 'BBBB', 'e');
+QUERY: INSERT INTO test_missing_target VALUES (5, 3, 'bbbb', 'F');
+QUERY: INSERT INTO test_missing_target VALUES (6, 4, 'cccc', 'g');
+QUERY: INSERT INTO test_missing_target VALUES (7, 4, 'cccc', 'h');
+QUERY: INSERT INTO test_missing_target VALUES (8, 4, 'CCCC', 'I');
+QUERY: INSERT INTO test_missing_target VALUES (9, 4, 'CCCC', 'j');
QUERY: SELECT c, count(*) FROM test_missing_target GROUP BY test_missing_target.c;
c |count
--------+-----
xxxx | 1
(4 rows)
-QUERY: SELECT a FROM test_missing_target ORDER BY upper(c);
+QUERY: SELECT a FROM test_missing_target ORDER BY upper(d);
a
-
+0
1
2
3
7
8
9
-0
(10 rows)
QUERY: SELECT count(b) FROM test_missing_target
-- select_having.sql
--
-SELECT d1, count(*) FROM DATETIME_TBL
- GROUP BY d1 HAVING count(*) > 1;
+-- load test data
+CREATE TABLE test_having (a int, b int, c char(8), d char);
+INSERT INTO test_having VALUES (0, 1, 'XXXX', 'A');
+INSERT INTO test_having VALUES (1, 2, 'AAAA', 'b');
+INSERT INTO test_having VALUES (2, 2, 'AAAA', 'c');
+INSERT INTO test_having VALUES (3, 3, 'BBBB', 'D');
+INSERT INTO test_having VALUES (4, 3, 'BBBB', 'e');
+INSERT INTO test_having VALUES (5, 3, 'bbbb', 'F');
+INSERT INTO test_having VALUES (6, 4, 'cccc', 'g');
+INSERT INTO test_having VALUES (7, 4, 'cccc', 'h');
+INSERT INTO test_having VALUES (8, 4, 'CCCC', 'I');
+INSERT INTO test_having VALUES (9, 4, 'CCCC', 'j');
+SELECT max(a) FROM test_having
+ GROUP BY lower(c) HAVING count(*) > 2 OR min(b) = 3;
+
+SELECT lower(c), count(c) FROM test_having
+ GROUP BY lower(c) HAVING count(*) > 2 OR min(a) = max(a);
+
+SELECT c, max(a) FROM test_having
+ GROUP BY c HAVING count(*) > 2 OR min(a) = max(a);
+
+DROP TABLE test_having;
-- - thomas 1998-07-09
-- load test data
-CREATE TABLE test_missing_target (a int, b int, c char(8));
-INSERT INTO test_missing_target VALUES (0, 1, 'XXXX');
-INSERT INTO test_missing_target VALUES (1, 2, 'AAAA');
-INSERT INTO test_missing_target VALUES (2, 2, 'AAAA');
-INSERT INTO test_missing_target VALUES (3, 3, 'BBBB');
-INSERT INTO test_missing_target VALUES (4, 3, 'BBBB');
-INSERT INTO test_missing_target VALUES (5, 3, 'bbbb');
-INSERT INTO test_missing_target VALUES (6, 4, 'cccc');
-INSERT INTO test_missing_target VALUES (7, 4, 'cccc');
-INSERT INTO test_missing_target VALUES (8, 4, 'CCCC');
-INSERT INTO test_missing_target VALUES (9, 4, 'CCCC');
+CREATE TABLE test_missing_target (a int, b int, c char(8), d char);
+INSERT INTO test_missing_target VALUES (0, 1, 'XXXX', 'A');
+INSERT INTO test_missing_target VALUES (1, 2, 'AAAA', 'b');
+INSERT INTO test_missing_target VALUES (2, 2, 'AAAA', 'c');
+INSERT INTO test_missing_target VALUES (3, 3, 'BBBB', 'D');
+INSERT INTO test_missing_target VALUES (4, 3, 'BBBB', 'e');
+INSERT INTO test_missing_target VALUES (5, 3, 'bbbb', 'F');
+INSERT INTO test_missing_target VALUES (6, 4, 'cccc', 'g');
+INSERT INTO test_missing_target VALUES (7, 4, 'cccc', 'h');
+INSERT INTO test_missing_target VALUES (8, 4, 'CCCC', 'I');
+INSERT INTO test_missing_target VALUES (9, 4, 'CCCC', 'j');
-- w/ existing GROUP BY target
FROM test_missing_target GROUP BY lower(c) ORDER BY lower(c);
-- w/o existing GROUP BY target
-SELECT a FROM test_missing_target ORDER BY upper(c);
+SELECT a FROM test_missing_target ORDER BY upper(d);
-- w/o existing ORDER BY target
SELECT count(b) FROM test_missing_target