~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/t/func_group.test

  • Committer: Monty Taylor
  • Date: 2008-10-14 16:33:44 UTC
  • mfrom: (512 drizzle)
  • mto: (511.1.5 codestyle)
  • mto: This revision was merged to the branch mainline in revision 515.
  • Revision ID: monty@inaugust.com-20081014163344-9xprk712n9hmbrzr
MergedĀ fromĀ trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
insert into t1 values (null,null,'');
28
28
select count(distinct a),count(distinct grp) from t1;
29
29
 
30
 
select sum(all a),count(all a),avg(all a),std(all a),variance(all a),bit_or(all a),bit_and(all a),min(all a),max(all a),min(all c),max(all c) from t1;
31
 
select grp, sum(a),count(a),avg(a),std(a),variance(a),bit_or(a),bit_and(a),min(a),max(a),min(c),max(c) from t1 group by grp;
32
 
--disable_warnings
33
 
select grp, sum(a)+count(a)+avg(a)+std(a)+variance(a)+bit_or(a)+bit_and(a)+min(a)+max(a)+min(c)+max(c) as sum from t1 group by grp;
34
 
--enable_warnings
35
 
 
36
30
create table t2 (grp int, a bigint, c char(10));
37
31
insert into t2 select grp,max(a)+max(grp),max(c) from t1 group by grp;
38
32
 
46
40
# Problem with std()
47
41
#
48
42
 
49
 
CREATE TABLE t1 (id int(11),value1 float(10,2));
 
43
CREATE TABLE t1 (id int,value1 float(10,2));
50
44
INSERT INTO t1 VALUES (1,0.00),(1,1.00), (1,2.00), (2,10.00), (2,11.00), (2,12.00); 
51
 
CREATE TABLE t2 (id int(11),name char(20)); 
 
45
CREATE TABLE t2 (id int,name char(20)); 
52
46
INSERT INTO t2 VALUES (1,'Set One'),(2,'Set Two'); 
53
47
select id, avg(value1), std(value1), variance(value1) from t1 group by id;
54
48
select name, avg(value1), std(value1), variance(value1) from t1, t2 where t1.id = t2.id group by t1.id;
73
67
#
74
68
# test of count
75
69
#
76
 
create table t1 (a int(6) primary key, c char(10), b text);
 
70
create table t1 (a int primary key, c char(10), b text);
77
71
INSERT INTO t1 VALUES (1,'1','1');
78
72
INSERT INTO t1 VALUES (2,'2','2');
79
73
INSERT INTO t1 VALUES (4,'4','4');
147
141
drop table t1,t2;
148
142
 
149
143
#
150
 
# Test of group function and NULL values
151
 
#
152
 
 
153
 
CREATE TABLE t1 (a int, b int);
154
 
select count(b), sum(b), avg(b), std(b), min(b), max(b), bit_and(b), bit_or(b) from t1;
155
 
select a,count(b), sum(b), avg(b), std(b), min(b), max(b), bit_and(b), bit_or(b) from t1 group by a;
156
 
insert into t1 values (1,null);
157
 
select a,count(b), sum(b), avg(b), std(b), min(b), max(b), bit_and(b), bit_or(b) from t1 group by a;
158
 
insert into t1 values (1,null);
159
 
insert into t1 values (2,null);
160
 
select a,count(b), sum(b), avg(b), std(b), min(b), max(b), bit_and(b), bit_or(b) from t1 group by a;
161
 
select SQL_BIG_RESULT a,count(b), sum(b), avg(b), std(b), min(b), max(b), bit_and(b), bit_or(b) from t1 group by a;
162
 
insert into t1 values (2,1);
163
 
select a,count(b), sum(b), avg(b), std(b), min(b), max(b), bit_and(b), bit_or(b) from t1 group by a;
164
 
select SQL_BIG_RESULT a,count(b), sum(b), avg(b), std(b), min(b), max(b), bit_and(b), bit_or(b) from t1 group by a;
165
 
insert into t1 values (3,1);
166
 
select a,count(b), sum(b), avg(b), std(b), min(b), max(b), bit_and(b), bit_or(b) from t1 group by a;
167
 
select SQL_BIG_RESULT a,count(b), sum(b), avg(b), std(b), min(b), max(b), bit_and(b), bit_or(b), bit_xor(b) from t1 group by a;
168
 
explain extended select SQL_BIG_RESULT a,count(b), sum(b), avg(b), std(b), min(b), max(b), bit_and(b), bit_or(b), bit_xor(b) from t1 group by a;
169
 
drop table t1;
170
 
 
171
 
#
172
 
# Bug #1972: test for bit_and(), bit_or() and negative values
173
 
174
 
create table t1 (col int);
175
 
insert into t1 values (-1), (-2), (-3);
176
 
select bit_and(col), bit_or(col) from t1;
177
 
select SQL_BIG_RESULT bit_and(col), bit_or(col) from t1 group by col;
178
 
drop table t1;
179
 
 
180
 
#
181
144
# Bug #3376: avg() and an empty table
182
145
#
183
146
 
398
361
#
399
362
# Bug #6658 MAX(column) returns incorrect coercibility
400
363
#
401
 
create table t1 (a char character set latin2);
 
364
create table t1 (a char);
402
365
insert into t1 values ('a'),('b');
403
 
select charset(max(a)), coercibility(max(a)),
404
 
       charset(min(a)), coercibility(min(a)) from t1;
405
366
show create table t1;
406
367
create table t2 select max(a),min(a) from t1;
407
368
show create table t2;
463
424
#
464
425
 
465
426
CREATE TABLE t1 (
466
 
  id int(10) NOT NULL auto_increment,
 
427
  id int NOT NULL auto_increment,
467
428
  val enum('one','two','three') NOT NULL default 'one',
468
429
  PRIMARY KEY  (id)
469
 
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
470
 
 
471
 
INSERT INTO t1 VALUES
472
 
(1,'one'),(2,'two'),(3,'three'),(4,'one'),(5,'two');
473
 
 
474
 
select val, count(*) from t1 group by val;
475
 
drop table t1;
476
 
 
477
 
CREATE TABLE t1 (
478
 
  id int(10) NOT NULL auto_increment,
479
 
  val set('one','two','three') NOT NULL default 'one',
480
 
  PRIMARY KEY  (id)
481
 
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
482
 
 
483
 
INSERT INTO t1 VALUES
484
 
(1,'one'),(2,'two'),(3,'three'),(4,'one'),(5,'two');
485
 
 
 
430
) ENGINE=MyISAM;
 
431
 
 
432
INSERT INTO t1 VALUES
 
433
(1,'one'),(2,'two'),(3,'three'),(4,'one'),(5,'two');
 
434
 
486
435
select val, count(*) from t1 group by val;
487
436
drop table t1;
488
437
 
563
512
EXPLAIN SELECT MAX(b) FROM t1;
564
513
DROP TABLE t1;
565
514
 
566
 
CREATE TABLE t1 (id int , b varchar(512), INDEX(b(250))) COLLATE latin1_bin;
567
 
INSERT INTO t1 VALUES
568
 
  (1,CONCAT(REPEAT('_', 250), "qq")), (1,CONCAT(REPEAT('_', 250), "zz")),
569
 
  (1,CONCAT(REPEAT('_', 250), "aa")), (1,CONCAT(REPEAT('_', 250), "ff"));
570
 
 
571
 
SELECT MAX(b) FROM t1;
572
 
EXPLAIN SELECT MAX(b) FROM t1;
573
 
DROP TABLE t1;
574
515
#
575
516
# Bug #16792  query with subselect, join, and group not returning proper values
576
517
#
580
521
SELECT (SELECT COUNT(DISTINCT t1.b)) FROM t1 GROUP BY t1.a;
581
522
SELECT (SELECT COUNT(DISTINCT 12)) FROM t1 GROUP BY t1.a;
582
523
# an attempt to test all aggregate function with no table.
583
 
SELECT AVG(2), BIT_AND(2), BIT_OR(2), BIT_XOR(2), COUNT(*), COUNT(12),
 
524
SELECT AVG(2), COUNT(*), COUNT(12),
584
525
       COUNT(DISTINCT 12), MIN(2),MAX(2),STD(2), VARIANCE(2),SUM(2),
585
526
       GROUP_CONCAT(2),GROUP_CONCAT(DISTINCT 2);
586
527
DROP TABLE t1;
593
534
create table t2 (ff double);
594
535
insert into t2 values (2.2);
595
536
select cast(sum(distinct ff) as decimal(5,2)) from t2;
596
 
select cast(sum(distinct ff) as signed) from t2;
 
537
select sum(distinct ff) from t2;
597
538
select cast(variance(ff) as decimal(10,3)) from t2;
598
539
select cast(min(ff) as decimal(5,2)) from t2;
599
540
 
600
541
create table t1 (df decimal(5,1));
601
542
insert into t1 values(1.1);
602
543
insert into t1 values(2.2);
603
 
select cast(sum(distinct df) as signed) from t1;
604
 
select cast(min(df) as signed) from t1;
 
544
select sum(distinct df) from t1;
 
545
select min(df) from t1;
605
546
select 1e8 * sum(distinct df) from t1;
606
547
select 1e8 * min(df) from t1;
607
548
 
616
557
# BUG#3190, WL#1639: Standard Deviation STDDEV - 2 different calculations
617
558
#
618
559
 
619
 
CREATE TABLE t1 (id int(11),value1 float(10,2));
 
560
CREATE TABLE t1 (id int,value1 float(10,2));
620
561
INSERT INTO t1 VALUES (1,0.00),(1,1.00), (1,2.00), (2,10.00), (2,11.00), (2,12.00), (2,13.00);
621
562
select id, stddev_pop(value1), var_pop(value1), stddev_samp(value1), var_samp(value1) from t1 group by id;
622
563
DROP TABLE t1;
687
628
CREATE TABLE t2 (a INT PRIMARY KEY, b INT);
688
629
INSERT INTO t2 VALUES (1,1), (3,3);
689
630
 
690
 
SELECT SQL_NO_CACHE 
 
631
SELECT 
691
632
  (SELECT SUM(c.a) FROM t1 ttt, t2 ccc 
692
633
   WHERE ttt.a = ccc.b AND ttt.a = t.a GROUP BY ttt.a) AS minid   
693
634
FROM t1 t, t2 c WHERE t.a = c.b;