1
drop table if exists t1,t2;
2
set @sav_dpi= @@div_precision_increment;
3
set div_precision_increment= 5;
4
show variables like 'div_precision_increment';
6
div_precision_increment 5
7
create table t1 (grp int, a bigint unsigned, c char(10) not null);
8
insert into t1 values (1,1,"a");
9
insert into t1 values (2,2,"b");
10
insert into t1 values (2,3,"c");
11
insert into t1 values (3,4,"E");
12
insert into t1 values (3,5,"C");
13
insert into t1 values (3,6,"D");
14
select a,c,sum(a) from t1 group by a;
22
select a,c,sum(a) from t1 where a > 10 group by a;
24
select sum(a) from t1 where a > 10;
27
select a from t1 order by rand(10);
35
select distinct a from t1 order by rand(10);
43
select count(distinct a),count(distinct grp) from t1;
44
count(distinct a) count(distinct grp)
46
insert into t1 values (null,null,'');
47
select count(distinct a),count(distinct grp) from t1;
48
count(distinct a) count(distinct grp)
50
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;
51
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)
52
21 6 3.50000 1.70783 2.91667 7 0 1 6 E
53
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;
54
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)
55
NULL NULL 0 NULL NULL NULL 0 18446744073709551615 NULL NULL
56
1 1 1 1.00000 0.00000 0.00000 1 1 1 1 a a
57
2 5 2 2.50000 0.50000 0.25000 3 2 2 3 b c
58
3 15 3 5.00000 0.81650 0.66667 7 4 4 6 C E
59
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;
65
create table t2 (grp int, a bigint unsigned, c char(10));
66
insert into t2 select grp,max(a)+max(grp),max(c) from t1 group by grp;
67
replace into t2 select grp, a, c from t1 limit 2,1;
76
CREATE TABLE t1 (id int(11),value1 float(10,2));
77
INSERT INTO t1 VALUES (1,0.00),(1,1.00), (1,2.00), (2,10.00), (2,11.00), (2,12.00);
78
CREATE TABLE t2 (id int(11),name char(20));
79
INSERT INTO t2 VALUES (1,'Set One'),(2,'Set Two');
80
select id, avg(value1), std(value1), variance(value1) from t1 group by id;
81
id avg(value1) std(value1) variance(value1)
82
1 1.0000000 0.816497 0.666667
83
2 11.0000000 0.816497 0.666667
84
select name, avg(value1), std(value1), variance(value1) from t1, t2 where t1.id = t2.id group by t1.id;
85
name avg(value1) std(value1) variance(value1)
86
Set One 1.0000000 0.816497 0.666667
87
Set Two 11.0000000 0.816497 0.666667
89
create table t1 (id int not null);
90
create table t2 (id int not null,rating int null);
91
insert into t1 values(1),(2),(3);
92
insert into t2 values(1, 3),(2, NULL),(2, NULL),(3, 2),(3, NULL);
93
select t1.id, avg(rating) from t1 left join t2 on ( t1.id = t2.id ) group by t1.id;
98
select sql_small_result t2.id, avg(rating) from t2 group by t2.id;
103
select sql_big_result t2.id, avg(rating) from t2 group by t2.id;
108
select sql_small_result t2.id, avg(rating+0.0e0) from t2 group by t2.id;
113
select sql_big_result t2.id, avg(rating+0.0e0) from t2 group by t2.id;
119
create table t1 (a smallint(6) primary key, c char(10), b text);
120
INSERT INTO t1 VALUES (1,'1','1');
121
INSERT INTO t1 VALUES (2,'2','2');
122
INSERT INTO t1 VALUES (4,'4','4');
123
select count(*) from t1;
126
select count(*) from t1 where a = 1;
129
select count(*) from t1 where a = 100;
132
select count(*) from t1 where a >= 10;
135
select count(a) from t1 where a = 1;
138
select count(a) from t1 where a = 100;
141
select count(a) from t1 where a >= 10;
144
select count(b) from t1 where b >= 2;
147
select count(b) from t1 where b >= 10;
150
select count(c) from t1 where c = 10;
154
CREATE TABLE t1 (d DATETIME, i INT);
155
INSERT INTO t1 VALUES (NOW(), 1);
156
SELECT COUNT(i), i, COUNT(i)*i FROM t1 GROUP BY i;
157
COUNT(i) i COUNT(i)*i
159
SELECT COUNT(i), (i+0), COUNT(i)*(i+0) FROM t1 GROUP BY i;
160
COUNT(i) (i+0) COUNT(i)*(i+0)
167
insert into t1 values (10.3,'nem'),(20.53,'monty'),(30.23,'sinisa');
168
insert into t1 values (30.13,'nem'),(20.98,'monty'),(10.45,'sinisa');
169
insert into t1 values (5.2,'nem'),(8.64,'monty'),(11.12,'sinisa');
170
select sum(num) from t1;
173
select sum(num) from t1 group by user;
179
create table t1 (a1 int, a2 char(3), key k1(a1), key k2(a2));
180
insert into t1 values(10,'aaa'), (10,null), (10,'bbb'), (20,'zzz');
181
create table t2(a1 char(3), a2 int, a3 real, key k1(a1), key k2(a2, a1));
188
select min(a2) from t1;
191
select max(t1.a1), max(t2.a2) from t1, t2;
192
max(t1.a1) max(t2.a2)
194
select max(t1.a1) from t1, t2;
197
select max(t2.a2), max(t1.a1) from t1, t2;
198
max(t2.a2) max(t1.a1)
200
explain select min(a2) from t1;
201
id select_type table type possible_keys key key_len ref rows Extra
202
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
203
explain select max(t1.a1), max(t2.a2) from t1, t2;
204
id select_type table type possible_keys key key_len ref rows Extra
205
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL No matching min/max row
206
insert into t2 values('AAA', 10, 0.5);
207
insert into t2 values('BBB', 20, 1.0);
208
select t1.a1, t1.a2, t2.a1, t2.a2 from t1,t2;
218
select max(t1.a1), max(t2.a1) from t1, t2 where t2.a2=9;
219
max(t1.a1) max(t2.a1)
221
select max(t2.a1), max(t1.a1) from t1, t2 where t2.a2=9;
222
max(t2.a1) max(t1.a1)
224
select t1.a1, t1.a2, t2.a1, t2.a2 from t1 left outer join t2 on t1.a1=10;
233
select max(t1.a2) from t1 left outer join t2 on t1.a1=10;
236
select max(t2.a1) from t2 left outer join t1 on t2.a2=10 where t2.a2=20;
239
select max(t2.a1) from t2 left outer join t1 on t2.a2=10 where t2.a2=10;
242
select max(t2.a1) from t1 left outer join t2 on t1.a2=t2.a1 and 1=0 where t2.a1='AAA';
245
select max(t1.a2),max(t2.a1) from t1 left outer join t2 on t1.a1=10;
246
max(t1.a2) max(t2.a1)
249
CREATE TABLE t1 (a int, b int);
250
select count(b), sum(b), avg(b), std(b), min(b), max(b), bit_and(b), bit_or(b) from t1;
251
count(b) sum(b) avg(b) std(b) min(b) max(b) bit_and(b) bit_or(b)
252
0 NULL NULL NULL NULL NULL 18446744073709551615 0
253
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;
254
a count(b) sum(b) avg(b) std(b) min(b) max(b) bit_and(b) bit_or(b)
255
insert into t1 values (1,null);
256
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;
257
a count(b) sum(b) avg(b) std(b) min(b) max(b) bit_and(b) bit_or(b)
258
1 0 NULL NULL NULL NULL NULL 18446744073709551615 0
259
insert into t1 values (1,null);
260
insert into t1 values (2,null);
261
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;
262
a count(b) sum(b) avg(b) std(b) min(b) max(b) bit_and(b) bit_or(b)
263
1 0 NULL NULL NULL NULL NULL 18446744073709551615 0
264
2 0 NULL NULL NULL NULL NULL 18446744073709551615 0
265
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;
266
a count(b) sum(b) avg(b) std(b) min(b) max(b) bit_and(b) bit_or(b)
267
1 0 NULL NULL NULL NULL NULL 18446744073709551615 0
268
2 0 NULL NULL NULL NULL NULL 18446744073709551615 0
269
insert into t1 values (2,1);
270
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;
271
a count(b) sum(b) avg(b) std(b) min(b) max(b) bit_and(b) bit_or(b)
272
1 0 NULL NULL NULL NULL NULL 18446744073709551615 0
273
2 1 1 1.00000 0.00000 1 1 1 1
274
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;
275
a count(b) sum(b) avg(b) std(b) min(b) max(b) bit_and(b) bit_or(b)
276
1 0 NULL NULL NULL NULL NULL 18446744073709551615 0
277
2 1 1 1.00000 0.00000 1 1 1 1
278
insert into t1 values (3,1);
279
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;
280
a count(b) sum(b) avg(b) std(b) min(b) max(b) bit_and(b) bit_or(b)
281
1 0 NULL NULL NULL NULL NULL 18446744073709551615 0
282
2 1 1 1.00000 0.00000 1 1 1 1
283
3 1 1 1.00000 0.00000 1 1 1 1
284
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;
285
a count(b) sum(b) avg(b) std(b) min(b) max(b) bit_and(b) bit_or(b) bit_xor(b)
286
1 0 NULL NULL NULL NULL NULL 18446744073709551615 0 0
287
2 1 1 1.00000 0.00000 1 1 1 1 1
288
3 1 1 1.00000 0.00000 1 1 1 1 1
289
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;
290
id select_type table type possible_keys key key_len ref rows filtered Extra
291
1 SIMPLE t1 ALL NULL NULL NULL NULL 5 100.00 Using filesort
293
Note 1003 select sql_big_result "test"."t1"."a" AS "a",count("test"."t1"."b") AS "count(b)",sum("test"."t1"."b") AS "sum(b)",avg("test"."t1"."b") AS "avg(b)",std("test"."t1"."b") AS "std(b)",min("test"."t1"."b") AS "min(b)",max("test"."t1"."b") AS "max(b)",bit_and("test"."t1"."b") AS "bit_and(b)",bit_or("test"."t1"."b") AS "bit_or(b)",bit_xor("test"."t1"."b") AS "bit_xor(b)" from "test"."t1" group by "test"."t1"."a"
295
create table t1 (col int);
296
insert into t1 values (-1), (-2), (-3);
297
select bit_and(col), bit_or(col) from t1;
298
bit_and(col) bit_or(col)
299
18446744073709551612 18446744073709551615
300
select SQL_BIG_RESULT bit_and(col), bit_or(col) from t1 group by col;
301
bit_and(col) bit_or(col)
302
18446744073709551613 18446744073709551613
303
18446744073709551614 18446744073709551614
304
18446744073709551615 18446744073709551615
306
create table t1 (a int);
307
select avg(2) from t1;
312
a1 char(3) primary key,
322
a1 char(3) primary key,
329
insert into t1 values('AME',0,'SEA',0.100,date'1942-02-19');
330
insert into t1 values('HBR',1,'SEA',0.085,date'1948-03-05');
331
insert into t1 values('BOT',2,'SEA',0.085,date'1951-11-29');
332
insert into t1 values('BMC',3,'SEA',0.085,date'1958-09-08');
333
insert into t1 values('TWU',0,'LAX',0.080,date'1969-10-05');
334
insert into t1 values('BDL',0,'DEN',0.080,date'1960-11-27');
335
insert into t1 values('DTX',1,'NYC',0.080,date'1961-05-04');
336
insert into t1 values('PLS',1,'WDC',0.075,date'1949-01-02');
337
insert into t1 values('ZAJ',2,'CHI',0.075,date'1960-06-15');
338
insert into t1 values('VVV',2,'MIN',0.075,date'1959-06-28');
339
insert into t1 values('GTM',3,'DAL',0.070,date'1977-09-23');
340
insert into t1 values('SSJ',null,'CHI',null,date'1974-03-19');
341
insert into t1 values('KKK',3,'ATL',null,null);
342
insert into t1 values('XXX',null,'MIN',null,null);
343
insert into t1 values('WWW',1,'LED',null,null);
344
insert into t2 values('TKF','Seattle','WA','AME');
345
insert into t2 values('LCC','Los Angeles','CA','TWU');
346
insert into t2 values('DEN','Denver','CO','BDL');
347
insert into t2 values('SDC','San Diego','CA','TWU');
348
insert into t2 values('NOL','New Orleans','LA','GTM');
349
insert into t2 values('LAK','Los Angeles','CA','TWU');
350
insert into t2 values('AAA','AAA','AA','AME');
353
AME 0 SEA 0.1 1942-02-19
354
HBR 1 SEA 0.085 1948-03-05
355
BOT 2 SEA 0.085 1951-11-29
356
BMC 3 SEA 0.085 1958-09-08
357
TWU 0 LAX 0.08 1969-10-05
358
BDL 0 DEN 0.08 1960-11-27
359
DTX 1 NYC 0.08 1961-05-04
360
PLS 1 WDC 0.075 1949-01-02
361
ZAJ 2 CHI 0.075 1960-06-15
362
VVV 2 MIN 0.075 1959-06-28
363
GTM 3 DAL 0.07 1977-09-23
364
SSJ NULL CHI NULL 1974-03-19
366
XXX NULL MIN NULL NULL
371
LCC Los Angeles CA TWU
374
NOL New Orleans LA GTM
375
LAK Los Angeles CA TWU
378
select min(a1) from t1;
379
id select_type table type possible_keys key key_len ref rows Extra
380
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
381
select min(a1) from t1;
385
select max(a4) from t1;
386
id select_type table type possible_keys key key_len ref rows Extra
387
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
388
select max(a4) from t1;
392
select min(a5), max(a5) from t1;
393
id select_type table type possible_keys key key_len ref rows Extra
394
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
395
select min(a5), max(a5) from t1;
397
1942-02-19 1977-09-23
399
select min(a3) from t1 where a2 = 2;
400
id select_type table type possible_keys key key_len ref rows Extra
401
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
402
select min(a3) from t1 where a2 = 2;
406
select min(a1), max(a1) from t1 where a4 = 0.080;
407
id select_type table type possible_keys key key_len ref rows Extra
408
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
409
select min(a1), max(a1) from t1 where a4 = 0.080;
413
select min(t1.a5), max(t2.a3) from t1, t2;
414
id select_type table type possible_keys key key_len ref rows Extra
415
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
416
select min(t1.a5), max(t2.a3) from t1, t2;
417
min(t1.a5) max(t2.a3)
420
select min(t1.a3), max(t2.a2) from t1, t2 where t1.a2 = 0 and t2.a3 = 'CA';
421
id select_type table type possible_keys key key_len ref rows Extra
422
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
423
select min(t1.a3), max(t2.a2) from t1, t2 where t1.a2 = 0 and t2.a3 = 'CA';
424
min(t1.a3) max(t2.a2)
427
select min(a1) from t1 where a1 > 'KKK';
428
id select_type table type possible_keys key key_len ref rows Extra
429
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
430
select min(a1) from t1 where a1 > 'KKK';
434
select min(a1) from t1 where a1 >= 'KKK';
435
id select_type table type possible_keys key key_len ref rows Extra
436
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
437
select min(a1) from t1 where a1 >= 'KKK';
441
select max(a3) from t1 where a2 = 2 and a3 < 'SEA';
442
id select_type table type possible_keys key key_len ref rows Extra
443
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
444
select max(a3) from t1 where a2 = 2 and a3 < 'SEA';
448
select max(a5) from t1 where a5 < date'1970-01-01';
449
id select_type table type possible_keys key key_len ref rows Extra
450
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
451
select max(a5) from t1 where a5 < date'1970-01-01';
455
select max(a3) from t1 where a2 is null;
456
id select_type table type possible_keys key key_len ref rows Extra
457
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
458
select max(a3) from t1 where a2 is null;
462
select max(a3) from t1 where a2 = 0 and a3 between 'K' and 'Q';
463
id select_type table type possible_keys key key_len ref rows Extra
464
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
465
select max(a3) from t1 where a2 = 0 and a3 between 'K' and 'Q';
469
select min(a1), max(a1) from t1 where a1 between 'A' and 'P';
470
id select_type table type possible_keys key key_len ref rows Extra
471
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
472
select min(a1), max(a1) from t1 where a1 between 'A' and 'P';
476
select max(a3) from t1 where a3 < 'SEA' and a2 = 2 and a3 <= 'MIN';
477
id select_type table type possible_keys key key_len ref rows Extra
478
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
479
select max(a3) from t1 where a3 < 'SEA' and a2 = 2 and a3 <= 'MIN';
483
select max(a3) from t1 where a3 = 'MIN' and a2 = 2;
484
id select_type table type possible_keys key key_len ref rows Extra
485
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
486
select max(a3) from t1 where a3 = 'MIN' and a2 = 2;
490
select max(a3) from t1 where a3 = 'DEN' and a2 = 2;
491
id select_type table type possible_keys key key_len ref rows Extra
492
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL No matching min/max row
493
select max(a3) from t1 where a3 = 'DEN' and a2 = 2;
497
select max(t1.a3), min(t2.a2) from t1, t2 where t1.a2 = 2 and t1.a3 < 'MIN' and t2.a3 = 'CA';
498
id select_type table type possible_keys key key_len ref rows Extra
499
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
500
select max(t1.a3), min(t2.a2) from t1, t2 where t1.a2 = 2 and t1.a3 < 'MIN' and t2.a3 = 'CA';
501
max(t1.a3) min(t2.a2)
504
select max(a3) from t1 where a2 is null and a2 = 2;
505
id select_type table type possible_keys key key_len ref rows Extra
506
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
507
select max(a3) from t1 where a2 is null and a2 = 2;
511
select max(a2) from t1 where a2 >= 1;
512
id select_type table type possible_keys key key_len ref rows Extra
513
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
514
select max(a2) from t1 where a2 >= 1;
518
select min(a3) from t1 where a2 = 2 and a3 < 'SEA';
519
id select_type table type possible_keys key key_len ref rows Extra
520
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
521
select min(a3) from t1 where a2 = 2 and a3 < 'SEA';
525
select min(a3) from t1 where a2 = 4;
526
id select_type table type possible_keys key key_len ref rows Extra
527
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL No matching min/max row
528
select min(a3) from t1 where a2 = 4;
532
select min(a3) from t1 where a2 = 2 and a3 > 'SEA';
533
id select_type table type possible_keys key key_len ref rows Extra
534
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL No matching min/max row
535
select min(a3) from t1 where a2 = 2 and a3 > 'SEA';
539
select (min(a4)+max(a4))/2 from t1;
540
id select_type table type possible_keys key key_len ref rows Extra
541
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
542
select (min(a4)+max(a4))/2 from t1;
546
select min(a3) from t1 where 2 = a2;
547
id select_type table type possible_keys key key_len ref rows Extra
548
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
549
select min(a3) from t1 where 2 = a2;
553
select max(a3) from t1 where a2 = 2 and 'SEA' > a3;
554
id select_type table type possible_keys key key_len ref rows Extra
555
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
556
select max(a3) from t1 where a2 = 2 and 'SEA' > a3;
560
select max(a3) from t1 where a2 = 2 and 'SEA' < a3;
561
id select_type table type possible_keys key key_len ref rows Extra
562
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL No matching min/max row
563
select max(a3) from t1 where a2 = 2 and 'SEA' < a3;
567
select min(a3) from t1 where a2 = 2 and a3 >= 'CHI';
568
id select_type table type possible_keys key key_len ref rows Extra
569
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
570
select min(a3) from t1 where a2 = 2 and a3 >= 'CHI';
574
select min(a3) from t1 where a2 = 2 and a3 >= 'CHI' and a3 < 'SEA';
575
id select_type table type possible_keys key key_len ref rows Extra
576
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
577
select min(a3) from t1 where a2 = 2 and a3 >= 'CHI' and a3 < 'SEA';
581
select min(a3) from t1 where a2 = 2 and a3 >= 'CHI' and a3 = 'MIN';
582
id select_type table type possible_keys key key_len ref rows Extra
583
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
584
select min(a3) from t1 where a2 = 2 and a3 >= 'CHI' and a3 = 'MIN';
588
select min(a3) from t1 where a2 = 2 and a3 >= 'SEA' and a3 = 'MIN';
589
id select_type table type possible_keys key key_len ref rows Extra
590
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
591
select min(a3) from t1 where a2 = 2 and a3 >= 'SEA' and a3 = 'MIN';
595
select min(t1.a1), min(t2.a4) from t1,t2 where t1.a1 < 'KKK' and t2.a4 < 'KKK';
596
id select_type table type possible_keys key key_len ref rows Extra
597
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
598
select min(t1.a1), min(t2.a4) from t1,t2 where t1.a1 < 'KKK' and t2.a4 < 'KKK';
599
min(t1.a1) min(t2.a4)
602
select min(a1) from t1 where a1 > 'KKK' or a1 < 'XXX';
603
id select_type table type possible_keys key key_len ref rows Extra
604
1 SIMPLE t1 index PRIMARY PRIMARY 3 NULL 15 Using where; Using index
606
select min(a1) from t1 where a1 != 'KKK';
607
id select_type table type possible_keys key key_len ref rows Extra
608
1 SIMPLE t1 index PRIMARY PRIMARY 3 NULL 15 Using where; Using index
610
select max(a3) from t1 where a2 < 2 and a3 < 'SEA';
611
id select_type table type possible_keys key key_len ref rows Extra
612
1 SIMPLE t1 range k1 k1 3 NULL 6 Using where; Using index
614
select max(t1.a3), min(t2.a2) from t1, t2 where t1.a2 = 2 and t1.a3 < 'MIN' and t2.a3 > 'CA';
615
id select_type table type possible_keys key key_len ref rows Extra
616
1 SIMPLE t1 range k1 k1 7 NULL 1 Using where; Using index
617
1 SIMPLE t2 range k1 k1 3 NULL 4 Using where; Using index; Using join buffer
619
select min(a4 - 0.01) from t1;
620
id select_type table type possible_keys key key_len ref rows Extra
621
1 SIMPLE t1 index NULL k2 12 NULL 15 Using index
623
select max(a4 + 0.01) from t1;
624
id select_type table type possible_keys key key_len ref rows Extra
625
1 SIMPLE t1 index NULL k2 12 NULL 15 Using index
627
select min(a3) from t1 where (a2 +1 ) is null;
628
id select_type table type possible_keys key key_len ref rows Extra
629
1 SIMPLE t1 index NULL k1 7 NULL 15 Using where; Using index
631
select min(a3) from t1 where (a2 + 1) = 2;
632
id select_type table type possible_keys key key_len ref rows Extra
633
1 SIMPLE t1 index NULL k1 7 NULL 15 Using where; Using index
635
select min(a3) from t1 where 2 = (a2 + 1);
636
id select_type table type possible_keys key key_len ref rows Extra
637
1 SIMPLE t1 index NULL k1 7 NULL 15 Using where; Using index
639
select min(a2) from t1 where a2 < 2 * a2 - 8;
640
id select_type table type possible_keys key key_len ref rows Extra
641
1 SIMPLE t1 index NULL k1 7 NULL 15 Using where; Using index
643
select min(a1) from t1 where a1 between a3 and 'KKK';
644
id select_type table type possible_keys key key_len ref rows Extra
645
1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 15 Using where
647
select min(a4) from t1 where (a4 + 0.01) between 0.07 and 0.08;
648
id select_type table type possible_keys key key_len ref rows Extra
649
1 SIMPLE t1 index NULL k2 12 NULL 15 Using where; Using index
651
select concat(min(t1.a1),min(t2.a4)) from t1, t2 where t2.a4 <> 'AME';
652
id select_type table type possible_keys key key_len ref rows Extra
653
1 SIMPLE t2 range k2 k2 4 NULL 6 Using where; Using index
654
1 SIMPLE t1 index NULL PRIMARY 3 NULL 15 Using index; Using join buffer
656
create table t1 (a char(10));
657
insert into t1 values ('a'),('b'),('c');
658
select coercibility(max(a)) from t1;
662
create table t1 (a char character set latin2);
663
insert into t1 values ('a'),('b');
664
select charset(max(a)), coercibility(max(a)),
665
charset(min(a)), coercibility(min(a)) from t1;
666
charset(max(a)) coercibility(max(a)) charset(min(a)) coercibility(min(a))
668
show create table t1;
670
t1 CREATE TABLE "t1" (
671
"a" char(1) CHARACTER SET latin2
672
) ENGINE=MyISAM DEFAULT CHARSET=latin1
673
create table t2 select max(a),min(a) from t1;
674
show create table t2;
676
t2 CREATE TABLE "t2" (
677
"max(a)" char(1) CHARACTER SET latin2,
678
"min(a)" char(1) CHARACTER SET latin2
679
) ENGINE=MyISAM DEFAULT CHARSET=latin1
681
create table t2 select concat(a) from t1;
682
show create table t2;
684
t2 CREATE TABLE "t2" (
685
"concat(a)" varchar(1) CHARACTER SET latin2
686
) ENGINE=MyISAM DEFAULT CHARSET=latin1
688
create table t1 (a int);
689
insert into t1 values (1);
690
select max(a) as b from t1 having b=1;
693
select a from t1 having a=1;
697
create table t1 (a int);
698
select variance(2) from t1;
701
select stddev(2) from t1;
705
create table t1 (a int);
706
insert into t1 values (1),(2);
707
SELECT COUNT(*) FROM t1;
710
SELECT COUNT(*) FROM t1;
713
SELECT COUNT(*) FROM t1;
717
create table t1 (a int, primary key(a));
718
insert into t1 values (1),(2);
719
SELECT max(a) FROM t1;
722
SELECT max(a) FROM t1;
725
SELECT max(a) FROM t1;
729
CREATE TABLE t1 (a int primary key);
730
INSERT INTO t1 VALUES (1),(2),(3),(4);
731
SELECT MAX(a) FROM t1 WHERE a > 5;
734
SELECT MIN(a) FROM t1 WHERE a < 0;
739
id int(10) unsigned NOT NULL auto_increment,
740
val enum('one','two','three') NOT NULL default 'one',
742
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
743
INSERT INTO t1 VALUES
744
(1,'one'),(2,'two'),(3,'three'),(4,'one'),(5,'two');
745
select val, count(*) from t1 group by val;
752
id int(10) unsigned NOT NULL auto_increment,
753
val set('one','two','three') NOT NULL default 'one',
755
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
756
INSERT INTO t1 VALUES
757
(1,'one'),(2,'two'),(3,'three'),(4,'one'),(5,'two');
758
select val, count(*) from t1 group by val;
764
create table t1(a int, b datetime);
765
insert into t1 values (1, NOW()), (2, NOW());
766
create table t2 select MAX(b) from t1 group by a;
767
show create table t2;
769
t2 CREATE TABLE "t2" (
771
) ENGINE=MyISAM DEFAULT CHARSET=latin1
773
create table t1(f1 datetime);
774
insert into t1 values (now());
775
create table t2 select f2 from (select max(now()) f2 from t1) a;
776
show columns from t2;
777
Field Type Null Key Default Extra
780
create table t2 select f2 from (select now() f2 from t1) a;
781
show columns from t2;
782
Field Type Null Key Default Extra
789
INDEX i_b_id(a,b,id),
792
INSERT INTO t1 VALUES
793
(1,1,4), (2,2,1), (3,1,3), (4,2,1), (5,1,1);
794
SELECT MAX(id) FROM t1 WHERE id < 3 AND a=2 AND b=6;
805
INSERT INTO t1 VALUES
806
(1,1,4), (2,2,1), (3,1,3), (4,2,1), (5,1,1);
807
SELECT MAX(id) FROM t1 WHERE id < 3 AND a=2 AND b=6;
811
CREATE TABLE t1 (id int PRIMARY KEY, b char(3), INDEX(b));
812
INSERT INTO t1 VALUES (1,'xx'), (2,'aa');
817
SELECT MAX(b) FROM t1 WHERE b < 'ppppp';
822
SELECT MAX(b) FROM t1 WHERE b < 'pp';
826
CREATE TABLE t1 (id int PRIMARY KEY, b char(16), INDEX(b(4)));
827
INSERT INTO t1 VALUES (1, 'xxxxbbbb'), (2, 'xxxxaaaa');
828
SELECT MAX(b) FROM t1;
831
EXPLAIN SELECT MAX(b) FROM t1;
832
id select_type table type possible_keys key key_len ref rows Extra
833
1 SIMPLE t1 ALL NULL NULL NULL NULL 2
835
CREATE TABLE t1 (id int , b varchar(512), INDEX(b(250))) COLLATE latin1_bin;
836
INSERT INTO t1 VALUES
837
(1,CONCAT(REPEAT('_', 250), "qq")), (1,CONCAT(REPEAT('_', 250), "zz")),
838
(1,CONCAT(REPEAT('_', 250), "aa")), (1,CONCAT(REPEAT('_', 250), "ff"));
839
SELECT MAX(b) FROM t1;
841
__________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________zz
842
EXPLAIN SELECT MAX(b) FROM t1;
843
id select_type table type possible_keys key key_len ref rows Extra
844
1 SIMPLE t1 ALL NULL NULL NULL NULL 4
846
CREATE TABLE t1 (a INT, b INT);
847
INSERT INTO t1 VALUES (1,1),(1,2),(2,3);
848
SELECT (SELECT COUNT(DISTINCT t1.b)) FROM t1 GROUP BY t1.a;
849
(SELECT COUNT(DISTINCT t1.b))
852
SELECT (SELECT COUNT(DISTINCT 12)) FROM t1 GROUP BY t1.a;
853
(SELECT COUNT(DISTINCT 12))
856
SELECT AVG(2), BIT_AND(2), BIT_OR(2), BIT_XOR(2), COUNT(*), COUNT(12),
857
COUNT(DISTINCT 12), MIN(2),MAX(2),STD(2), VARIANCE(2),SUM(2),
858
GROUP_CONCAT(2),GROUP_CONCAT(DISTINCT 2);
859
AVG(2) BIT_AND(2) BIT_OR(2) BIT_XOR(2) COUNT(*) COUNT(12) COUNT(DISTINCT 12) MIN(2) MAX(2) STD(2) VARIANCE(2) SUM(2) GROUP_CONCAT(2) GROUP_CONCAT(DISTINCT 2)
860
2.00000 2 2 2 1 1 1 2 2 0.00000 0.00000 2 2 2
862
create table t2 (ff double);
863
insert into t2 values (2.2);
864
select cast(sum(distinct ff) as decimal(5,2)) from t2;
865
cast(sum(distinct ff) as decimal(5,2))
867
select cast(sum(distinct ff) as signed) from t2;
868
cast(sum(distinct ff) as signed)
870
select cast(variance(ff) as decimal(10,3)) from t2;
871
cast(variance(ff) as decimal(10,3))
873
select cast(min(ff) as decimal(5,2)) from t2;
874
cast(min(ff) as decimal(5,2))
876
create table t1 (df decimal(5,1));
877
insert into t1 values(1.1);
878
insert into t1 values(2.2);
879
select cast(sum(distinct df) as signed) from t1;
880
cast(sum(distinct df) as signed)
882
select cast(min(df) as signed) from t1;
883
cast(min(df) as signed)
885
select 1e8 * sum(distinct df) from t1;
886
1e8 * sum(distinct df)
888
select 1e8 * min(df) from t1;
891
create table t3 (ifl int);
892
insert into t3 values(1), (2);
893
select cast(min(ifl) as decimal(5,2)) from t3;
894
cast(min(ifl) as decimal(5,2))
896
drop table t1, t2, t3;
897
CREATE TABLE t1 (id int(11),value1 float(10,2));
898
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);
899
select id, stddev_pop(value1), var_pop(value1), stddev_samp(value1), var_samp(value1) from t1 group by id;
900
id stddev_pop(value1) var_pop(value1) stddev_samp(value1) var_samp(value1)
901
1 0.816497 0.666667 1.000000 1.000000
902
2 1.118034 1.250000 1.290994 1.666667
904
CREATE TABLE t1 (col1 decimal(16,12));
905
INSERT INTO t1 VALUES (-5.00000000001),(-5.00000000002),(-5.00000000003),(-5.00000000000),(-5.00000000001),(-5.00000000002);
906
insert into t1 select * from t1;
907
select col1,count(col1),sum(col1),avg(col1) from t1 group by col1;
908
col1 count(col1) sum(col1) avg(col1)
909
-5.000000000030 2 -10.000000000060 -5.00000000003000000
910
-5.000000000020 4 -20.000000000080 -5.00000000002000000
911
-5.000000000010 4 -20.000000000040 -5.00000000001000000
912
-5.000000000000 2 -10.000000000000 -5.00000000000000000
914
create table t1 (col1 decimal(16,12));
915
insert into t1 values (-5.00000000001);
916
insert into t1 values (-5.00000000001);
917
select col1,sum(col1),max(col1),min(col1) from t1 group by col1;
918
col1 sum(col1) max(col1) min(col1)
919
-5.000000000010 -10.000000000020 -5.000000000010 -5.000000000010
921
insert into t1 values (5.00000000001);
922
insert into t1 values (5.00000000001);
923
select col1,sum(col1),max(col1),min(col1) from t1 group by col1;
924
col1 sum(col1) max(col1) min(col1)
925
5.000000000010 10.000000000020 5.000000000010 5.000000000010
927
CREATE TABLE t1 (a VARCHAR(400));
928
INSERT INTO t1 (a) VALUES ("A"), ("a"), ("a "), ("a "),
929
("B"), ("b"), ("b "), ("b ");
930
SELECT COUNT(DISTINCT a) FROM t1;
934
CREATE TABLE t1 (a int, b int, c int);
935
INSERT INTO t1 (a, b, c) VALUES
936
(1,1,1), (1,1,2), (1,1,3),
937
(1,2,1), (1,2,2), (1,2,3),
938
(1,3,1), (1,3,2), (1,3,3),
939
(2,1,1), (2,1,2), (2,1,3),
940
(2,2,1), (2,2,2), (2,2,3),
941
(2,3,1), (2,3,2), (2,3,3),
942
(3,1,1), (3,1,2), (3,1,3),
943
(3,2,1), (3,2,2), (3,2,3),
944
(3,3,1), (3,3,2), (3,3,3);
945
SELECT b/c as v, a FROM t1 ORDER BY v;
974
SELECT b/c as v, SUM(a) FROM t1 GROUP BY v;
983
SELECT SUM(a) FROM t1 GROUP BY b/c;
993
set div_precision_increment= @sav_dpi;
994
CREATE TABLE t1 (a INT PRIMARY KEY, b INT);
995
INSERT INTO t1 VALUES (1,1), (2,2);
996
CREATE TABLE t2 (a INT PRIMARY KEY, b INT);
997
INSERT INTO t2 VALUES (1,1), (3,3);
999
(SELECT SUM(c.a) FROM t1 ttt, t2 ccc
1000
WHERE ttt.a = ccc.b AND ttt.a = t.a GROUP BY ttt.a) AS minid
1001
FROM t1 t, t2 c WHERE t.a = c.b;
1005
create table t1 select variance(0);
1006
show create table t1;
1008
t1 CREATE TABLE "t1" (
1009
"variance(0)" double(8,4)
1010
) ENGINE=MyISAM DEFAULT CHARSET=latin1
1012
create table t1 select stddev(0);
1013
show create table t1;
1015
t1 CREATE TABLE "t1" (
1016
"stddev(0)" double(8,4)
1017
) ENGINE=MyISAM DEFAULT CHARSET=latin1
1019
create table bug22555 (i smallint primary key auto_increment, s1 smallint, s2 smallint, e decimal(30,10), o double);
1020
insert into bug22555 (s1, s2, e, o) values (53, 78, 11.4276528, 6.828112), (17, 78, 5.916793, 1.8502951), (18, 76, 2.679231, 9.17975591), (31, 62, 6.07831, 0.1), (19, 41, 5.37463, 15.1), (83, 73, 14.567426, 7.959222), (92, 53, 6.10151, 13.1856852), (7, 12, 13.92272, 3.442007), (92, 35, 11.95358909, 6.01376678), (38, 84, 2.572, 7.904571);
1021
select std(s1/s2) from bug22555 group by i;
1033
select std(e) from bug22555 group by i;
1045
select std(o) from bug22555 group by i;
1057
drop table bug22555;
1058
create table bug22555 (i smallint, s1 smallint, s2 smallint, o1 double, o2 double, e1 decimal, e2 decimal);
1059
insert into bug22555 values (1,53,78,53,78,53,78),(2,17,78,17,78,17,78),(3,18,76,18,76,18,76);
1060
select i, count(*) from bug22555 group by i;
1065
select std(s1/s2) from bug22555 where i=1;
1068
select std(s1/s2) from bug22555 where i=2;
1071
select std(s1/s2) from bug22555 where i=3;
1074
select std(s1/s2) from bug22555 where i=1 group by i;
1077
select std(s1/s2) from bug22555 where i=2 group by i;
1080
select std(s1/s2) from bug22555 where i=3 group by i;
1083
select std(s1/s2) from bug22555 group by i order by i;
1088
select i, count(*), std(o1/o2) from bug22555 group by i order by i;
1089
i count(*) std(o1/o2)
1093
select i, count(*), std(e1/e2) from bug22555 group by i order by i;
1094
i count(*) std(e1/e2)
1098
set @saved_div_precision_increment=@@div_precision_increment;
1099
set div_precision_increment=19;
1100
select i, count(*), variance(s1/s2) from bug22555 group by i order by i;
1101
i count(*) variance(s1/s2)
1102
1 1 0.000000000000000000000000000000
1103
2 1 0.000000000000000000000000000000
1104
3 1 0.000000000000000000000000000000
1105
select i, count(*), variance(o1/o2) from bug22555 group by i order by i;
1106
i count(*) variance(o1/o2)
1110
select i, count(*), variance(e1/e2) from bug22555 group by i order by i;
1111
i count(*) variance(e1/e2)
1112
1 1 0.000000000000000000000000000000
1113
2 1 0.000000000000000000000000000000
1114
3 1 0.000000000000000000000000000000
1115
select i, count(*), std(s1/s2) from bug22555 group by i order by i;
1116
i count(*) std(s1/s2)
1117
1 1 0.000000000000000000000000000000
1118
2 1 0.000000000000000000000000000000
1119
3 1 0.000000000000000000000000000000
1120
select i, count(*), std(o1/o2) from bug22555 group by i order by i;
1121
i count(*) std(o1/o2)
1125
select i, count(*), std(e1/e2) from bug22555 group by i order by i;
1126
i count(*) std(e1/e2)
1127
1 1 0.000000000000000000000000000000
1128
2 1 0.000000000000000000000000000000
1129
3 1 0.000000000000000000000000000000
1130
set div_precision_increment=20;
1131
select i, count(*), variance(s1/s2) from bug22555 group by i order by i;
1132
i count(*) variance(s1/s2)
1133
1 1 0.000000000000000000000000000000
1134
2 1 0.000000000000000000000000000000
1135
3 1 0.000000000000000000000000000000
1136
select i, count(*), variance(o1/o2) from bug22555 group by i order by i;
1137
i count(*) variance(o1/o2)
1141
select i, count(*), variance(e1/e2) from bug22555 group by i order by i;
1142
i count(*) variance(e1/e2)
1143
1 1 0.000000000000000000000000000000
1144
2 1 0.000000000000000000000000000000
1145
3 1 0.000000000000000000000000000000
1146
select i, count(*), std(s1/s2) from bug22555 group by i order by i;
1147
i count(*) std(s1/s2)
1148
1 1 0.000000000000000000000000000000
1149
2 1 0.000000000000000000000000000000
1150
3 1 0.000000000000000000000000000000
1151
select i, count(*), std(o1/o2) from bug22555 group by i order by i;
1152
i count(*) std(o1/o2)
1156
select i, count(*), std(e1/e2) from bug22555 group by i order by i;
1157
i count(*) std(e1/e2)
1158
1 1 0.000000000000000000000000000000
1159
2 1 0.000000000000000000000000000000
1160
3 1 0.000000000000000000000000000000
1161
set @@div_precision_increment=@saved_div_precision_increment;
1162
insert into bug22555 values (1,53,78,53,78,53,78),(2,17,78,17,78,17,78),(3,18,76,18,76,18,76);
1163
insert into bug22555 values (1,53,78,53,78,53,78),(2,17,78,17,78,17,78),(3,18,76,18,76,18,76);
1164
insert into bug22555 values (1,53,78,53,78,53,78),(2,17,78,17,78,17,78),(3,18,76,18,76,18,76);
1165
select i, count(*), std(s1/s2) from bug22555 group by i order by i;
1166
i count(*) std(s1/s2)
1170
select i, count(*), round(std(o1/o2), 16) from bug22555 group by i order by i;
1171
i count(*) round(std(o1/o2), 16)
1172
1 4 0.0000000000000000
1173
2 4 0.0000000000000000
1174
3 4 0.0000000000000000
1175
select i, count(*), std(e1/e2) from bug22555 group by i order by i;
1176
i count(*) std(e1/e2)
1180
select std(s1/s2) from bug22555;
1183
select std(o1/o2) from bug22555;
1186
select std(e1/e2) from bug22555;
1189
set @saved_div_precision_increment=@@div_precision_increment;
1190
set div_precision_increment=19;
1191
select i, count(*), std(s1/s2) from bug22555 group by i order by i;
1192
i count(*) std(s1/s2)
1193
1 4 0.000000000000000000000000000000
1194
2 4 0.000000000000000000000000000000
1195
3 4 0.000000000000000000000000000000
1196
select i, count(*), round(std(o1/o2), 16) from bug22555 group by i order by i;
1197
i count(*) round(std(o1/o2), 16)
1198
1 4 0.0000000000000000
1199
2 4 0.0000000000000000
1200
3 4 0.0000000000000000
1201
select i, count(*), std(e1/e2) from bug22555 group by i order by i;
1202
i count(*) std(e1/e2)
1203
1 4 0.000000000000000000000000000000
1204
2 4 0.000000000000000000000000000000
1205
3 4 0.000000000000000000000000000000
1206
select round(std(s1/s2), 17) from bug22555;
1207
round(std(s1/s2), 17)
1209
select std(o1/o2) from bug22555;
1212
select round(std(e1/e2), 17) from bug22555;
1213
round(std(e1/e2), 17)
1215
set div_precision_increment=20;
1216
select i, count(*), std(s1/s2) from bug22555 group by i order by i;
1217
i count(*) std(s1/s2)
1218
1 4 0.000000000000000000000000000000
1219
2 4 0.000000000000000000000000000000
1220
3 4 0.000000000000000000000000000000
1221
select i, count(*), round(std(o1/o2), 16) from bug22555 group by i order by i;
1222
i count(*) round(std(o1/o2), 16)
1223
1 4 0.0000000000000000
1224
2 4 0.0000000000000000
1225
3 4 0.0000000000000000
1226
select i, count(*), std(e1/e2) from bug22555 group by i order by i;
1227
i count(*) std(e1/e2)
1228
1 4 0.000000000000000000000000000000
1229
2 4 0.000000000000000000000000000000
1230
3 4 0.000000000000000000000000000000
1231
select round(std(s1/s2), 17) from bug22555;
1232
round(std(s1/s2), 17)
1234
select std(o1/o2) from bug22555;
1237
select round(std(e1/e2), 17) from bug22555;
1238
round(std(e1/e2), 17)
1240
set @@div_precision_increment=@saved_div_precision_increment;
1241
drop table bug22555;
1242
create table bug22555 (s smallint, o double, e decimal);
1243
insert into bug22555 values (1,1,1),(2,2,2),(3,3,3),(6,6,6),(7,7,7);
1244
select var_samp(s), var_pop(s) from bug22555;
1245
var_samp(s) var_pop(s)
1247
select var_samp(o), var_pop(o) from bug22555;
1248
var_samp(o) var_pop(o)
1250
select var_samp(e), var_pop(e) from bug22555;
1251
var_samp(e) var_pop(e)
1253
drop table bug22555;
1254
create table bug22555 (s smallint, o double, e decimal);
1255
insert into bug22555 values (null,null,null),(null,null,null);
1256
select var_samp(s) as 'null', var_pop(s) as 'null' from bug22555;
1259
select var_samp(o) as 'null', var_pop(o) as 'null' from bug22555;
1262
select var_samp(e) as 'null', var_pop(e) as 'null' from bug22555;
1265
insert into bug22555 values (1,1,1);
1266
select var_samp(s) as 'null', var_pop(s) as '0' from bug22555;
1269
select var_samp(o) as 'null', var_pop(o) as '0' from bug22555;
1272
select var_samp(e) as 'null', var_pop(e) as '0' from bug22555;
1275
insert into bug22555 values (2,2,2);
1276
select var_samp(s) as '0.5', var_pop(s) as '0.25' from bug22555;
1279
select var_samp(o) as '0.5', var_pop(o) as '0.25' from bug22555;
1282
select var_samp(e) as '0.5', var_pop(e) as '0.25' from bug22555;
1285
drop table bug22555;
1286
create table t1 (a decimal(20));
1287
insert into t1 values (12345678901234567890);
1288
select count(a) from t1;
1291
select count(distinct a) from t1;
1295
CREATE TABLE t1 (a INT, b INT);
1296
INSERT INTO t1 VALUES (1,1),(1,2),(1,3),(1,4),(1,5),(1,6),(1,7),(1,8);
1297
INSERT INTO t1 SELECT a, b+8 FROM t1;
1298
INSERT INTO t1 SELECT a, b+16 FROM t1;
1299
INSERT INTO t1 SELECT a, b+32 FROM t1;
1300
INSERT INTO t1 SELECT a, b+64 FROM t1;
1301
INSERT INTO t1 SELECT a, b+128 FROM t1;
1302
INSERT INTO t1 SELECT a, b+256 FROM t1;
1303
INSERT INTO t1 SELECT a, b+512 FROM t1;
1304
INSERT INTO t1 SELECT a, b+1024 FROM t1;
1305
INSERT INTO t1 SELECT a, b+2048 FROM t1;
1306
INSERT INTO t1 SELECT a, b+4096 FROM t1;
1307
INSERT INTO t1 SELECT a, b+8192 FROM t1;
1308
INSERT INTO t1 SELECT a, b+16384 FROM t1;
1309
INSERT INTO t1 SELECT a, b+32768 FROM t1;
1310
SELECT a,COUNT(DISTINCT b) AS cnt FROM t1 GROUP BY a HAVING cnt > 50;
1313
SELECT a,SUM(DISTINCT b) AS sumation FROM t1 GROUP BY a HAVING sumation > 50;
1316
SELECT a,AVG(DISTINCT b) AS average FROM t1 GROUP BY a HAVING average > 50;
1320
CREATE TABLE t1 ( a INT, b INT, KEY(a) );
1321
INSERT INTO t1 VALUES (NULL, 1), (NULL, 2);
1322
EXPLAIN SELECT MIN(a), MIN(b) FROM t1;
1323
id select_type table type possible_keys key key_len ref rows Extra
1324
1 SIMPLE t1 ALL NULL NULL NULL NULL 2
1325
SELECT MIN(a), MIN(b) FROM t1;
1328
CREATE TABLE t2( a INT, b INT, c INT, KEY(a, b) );
1329
INSERT INTO t2 ( a, b, c ) VALUES ( 1, NULL, 2 ), ( 1, 3, 4 ), ( 1, 4, 4 );
1330
EXPLAIN SELECT MIN(b), MIN(c) FROM t2 WHERE a = 1;
1331
id select_type table type possible_keys key key_len ref rows Extra
1332
1 SIMPLE t2 ref a a 5 const 2
1333
SELECT MIN(b), MIN(c) FROM t2 WHERE a = 1;
1336
CREATE TABLE t3 (a INT, b INT, c int, KEY(a, b));
1337
INSERT INTO t3 VALUES (1, NULL, 1), (2, NULL, 2), (2, NULL, 2), (3, NULL, 3);
1338
EXPLAIN SELECT MIN(a), MIN(b) FROM t3 where a = 2;
1339
id select_type table type possible_keys key key_len ref rows Extra
1340
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
1341
SELECT MIN(a), MIN(b) FROM t3 where a = 2;
1344
CREATE TABLE t4 (a INT, b INT, c int, KEY(a, b));
1345
INSERT INTO t4 VALUES (1, 1, 1), (2, NULL, 2), (2, NULL, 2), (3, 1, 3);
1346
EXPLAIN SELECT MIN(a), MIN(b) FROM t4 where a = 2;
1347
id select_type table type possible_keys key key_len ref rows Extra
1348
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
1349
SELECT MIN(a), MIN(b) FROM t4 where a = 2;
1352
SELECT MIN(b), min(c) FROM t4 where a = 2;
1355
CREATE TABLE t5( a INT, b INT, KEY( a, b) );
1356
INSERT INTO t5 VALUES( 1, 1 ), ( 1, 2 );
1357
EXPLAIN SELECT MIN(a), MIN(b) FROM t5 WHERE a = 1;
1358
id select_type table type possible_keys key key_len ref rows Extra
1359
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
1360
SELECT MIN(a), MIN(b) FROM t5 WHERE a = 1;
1363
SELECT MIN(a), MIN(b) FROM t5 WHERE a = 1 and b > 1;
1366
DROP TABLE t1, t2, t3, t4, t5;
1367
CREATE TABLE t1 (a int, b date NOT NULL, KEY k1 (a,b));
1368
SELECT MIN(b) FROM t1 WHERE a=1 AND b>'2007-08-01';
1372
CREATE TABLE t1(a DOUBLE);
1373
INSERT INTO t1 VALUES (10), (20);
1374
SELECT AVG(a), CAST(AVG(a) AS DECIMAL) FROM t1;
1375
AVG(a) CAST(AVG(a) AS DECIMAL)