]> granicus.if.org Git - postgresql/blob - src/test/regress/sql/select_having.sql
Back out cleanup patch. Got old version and needs work.
[postgresql] / src / test / regress / sql / select_having.sql
1 --
2 -- SELECT_HAVING
3 --
4
5 -- load test data
6 CREATE TABLE test_having (a int, b int, c char(8), d char);
7 INSERT INTO test_having VALUES (0, 1, 'XXXX', 'A');
8 INSERT INTO test_having VALUES (1, 2, 'AAAA', 'b');
9 INSERT INTO test_having VALUES (2, 2, 'AAAA', 'c');
10 INSERT INTO test_having VALUES (3, 3, 'BBBB', 'D');
11 INSERT INTO test_having VALUES (4, 3, 'BBBB', 'e');
12 INSERT INTO test_having VALUES (5, 3, 'bbbb', 'F');
13 INSERT INTO test_having VALUES (6, 4, 'cccc', 'g');
14 INSERT INTO test_having VALUES (7, 4, 'cccc', 'h');
15 INSERT INTO test_having VALUES (8, 4, 'CCCC', 'I');
16 INSERT INTO test_having VALUES (9, 4, 'CCCC', 'j');
17
18 SELECT b, c FROM test_having
19         GROUP BY b, c HAVING count(*) = 1;
20
21 SELECT lower(c), count(c) FROM test_having
22         GROUP BY lower(c) HAVING count(*) > 2 OR min(a) = max(a);
23
24 SELECT c, max(a) FROM test_having
25         GROUP BY c HAVING count(*) > 2 OR min(a) = max(a);
26
27 DROP TABLE test_having;
28