blob: 0fa0850d818072f71482ce3486f1c0c9aa8ac165 [file] [log] [blame]
drh191b6902000-06-08 11:13:01 +00001# Copyright (c) 1999, 2000 D. Richard Hipp
2#
3# This program is free software; you can redistribute it and/or
4# modify it under the terms of the GNU General Public
5# License as published by the Free Software Foundation; either
6# version 2 of the License, or (at your option) any later version.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11# General Public License for more details.
12#
13# You should have received a copy of the GNU General Public
14# License along with this library; if not, write to the
15# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16# Boston, MA 02111-1307, USA.
17#
18# Author contact information:
19# drh@hwaci.com
20# http://www.hwaci.com/drh/
21#
22#***********************************************************************
23# This file implements regression tests for SQLite library. The
24# focus of this file is testing aggregate functions and the
25# GROUP BY and HAVING clauses of SELECT statements.
26#
drhaaf88722000-06-08 11:25:00 +000027# $Id: select5.test,v 1.2 2000/06/08 11:25:01 drh Exp $
drh191b6902000-06-08 11:13:01 +000028
29set testdir [file dirname $argv0]
30source $testdir/tester.tcl
31
32# Build some test data
33#
34set fd [open data1.txt w]
35for {set i 1} {$i<32} {incr i} {
36 for {set j 0} {pow(2,$j)<$i} {incr j} {}
37 puts $fd "[expr {32-$i}]\t[expr {10-$j}]"
38}
39close $fd
40execsql {
41 CREATE TABLE t1(x int, y int);
42 COPY t1 FROM 'data1.txt'
43}
44file delete data1.txt
45
46do_test select5-1.0 {
47 execsql {SELECT DISTINCT y FROM t1 ORDER BY y}
48} {5 6 7 8 9 10}
49
50# Sort by an aggregate function.
51#
52do_test select5-1.1 {
53 execsql {SELECT y, count(*) FROM t1 GROUP BY y ORDER BY y}
54} {5 15 6 8 7 4 8 2 9 1 10 1}
55do_test select5-1.2 {
56 execsql {SELECT y, count(*) FROM t1 GROUP BY y ORDER BY count(*), y}
57} {9 1 10 1 8 2 7 4 6 8 5 15}
drhaaf88722000-06-08 11:25:00 +000058do_test select5-1.3 {
59 execsql {SELECT count(*), y FROM t1 GROUP BY y ORDER BY count(*), y}
60} {1 9 1 10 2 8 4 7 8 6 15 5}
drh191b6902000-06-08 11:13:01 +000061
62finish_test