~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/r/pbxt/func_group.result

  • Committer: Stewart Smith
  • Date: 2010-11-03 03:27:09 UTC
  • mto: (1902.1.1 build) (1910.1.2 build)
  • mto: This revision was merged to the branch mainline in revision 1903.
  • Revision ID: stewart@flamingspork.com-20101103032709-oyvfrc6eb8fzj0mr
fix docs warning: docs/unlock.rst:2: (WARNING/2) Title underline too short.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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';
 
5
Variable_name   Value
 
6
div_precision_increment 5
 
7
create table t1 (grp int, a bigint, 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;
 
15
a       c       sum(a)
 
16
1       a       1
 
17
2       b       2
 
18
3       c       3
 
19
4       E       4
 
20
5       C       5
 
21
6       D       6
 
22
select a,c,sum(a) from t1 where a > 10 group by a;
 
23
a       c       sum(a)
 
24
select sum(a) from t1 where a > 10;
 
25
sum(a)
 
26
NULL
 
27
select a from t1 order by rand(10);
 
28
a
 
29
2
 
30
6
 
31
1
 
32
3
 
33
5
 
34
4
 
35
select distinct a from t1 order by rand(10);
 
36
a
 
37
2
 
38
6
 
39
1
 
40
3
 
41
5
 
42
4
 
43
select count(distinct a),count(distinct grp) from t1;
 
44
count(distinct a)       count(distinct grp)
 
45
6       3
 
46
insert into t1 values (null,null,'');
 
47
select count(distinct a),count(distinct grp) from t1;
 
48
count(distinct a)       count(distinct grp)
 
49
6       3
 
50
create table t2 (grp int, a bigint, c char(10));
 
51
insert into t2 select grp,max(a)+max(grp),max(c) from t1 group by grp;
 
52
replace into t2 select grp, a, c from t1 limit 2,1;
 
53
select * from t2;
 
54
grp     a       c
 
55
NULL    NULL    
 
56
1       2       a
 
57
2       5       c
 
58
3       9       E
 
59
2       3       c
 
60
drop table t1,t2;
 
61
CREATE TABLE t1 (id int,value1 float(10,2));
 
62
INSERT INTO t1 VALUES (1,0.00),(1,1.00), (1,2.00), (2,10.00), (2,11.00), (2,12.00);
 
63
CREATE TABLE t2 (id int,name char(20));
 
64
INSERT INTO t2 VALUES (1,'Set One'),(2,'Set Two');
 
65
select id, avg(value1), std(value1), variance(value1) from t1 group by id;
 
66
id      avg(value1)     std(value1)     variance(value1)
 
67
1       1.0000000       0.816497        0.666667
 
68
2       11.0000000      0.816497        0.666667
 
69
select name, avg(value1), std(value1), variance(value1) from t1, t2 where t1.id = t2.id group by t1.id;
 
70
name    avg(value1)     std(value1)     variance(value1)
 
71
Set One 1.0000000       0.816497        0.666667
 
72
Set Two 11.0000000      0.816497        0.666667
 
73
drop table t1,t2;
 
74
create table t1 (id int not null);
 
75
create table t2 (id int not null,rating int null);
 
76
insert into t1 values(1),(2),(3);
 
77
insert into t2 values(1, 3),(2, NULL),(2, NULL),(3, 2),(3, NULL);
 
78
select t1.id, avg(rating) from t1 left join t2 on ( t1.id = t2.id ) group by t1.id;
 
79
id      avg(rating)
 
80
1       3.00000
 
81
2       NULL
 
82
3       2.00000
 
83
select sql_small_result t2.id, avg(rating) from t2 group by t2.id;
 
84
id      avg(rating)
 
85
1       3.00000
 
86
2       NULL
 
87
3       2.00000
 
88
select sql_big_result t2.id, avg(rating) from t2 group by t2.id;
 
89
id      avg(rating)
 
90
1       3.00000
 
91
2       NULL
 
92
3       2.00000
 
93
select sql_small_result t2.id, avg(rating+0.0e0) from t2 group by t2.id;
 
94
id      avg(rating+0.0e0)
 
95
1       3
 
96
2       NULL
 
97
3       2
 
98
select sql_big_result t2.id, avg(rating+0.0e0) from t2 group by t2.id;
 
99
id      avg(rating+0.0e0)
 
100
1       3
 
101
2       NULL
 
102
3       2
 
103
drop table t1,t2;
 
104
create table t1 (a int primary key, c char(10), b text);
 
105
INSERT INTO t1 VALUES (1,'1','1');
 
106
INSERT INTO t1 VALUES (2,'2','2');
 
107
INSERT INTO t1 VALUES (4,'4','4');
 
108
select count(*) from t1;
 
109
count(*)
 
110
3
 
111
select count(*) from t1 where a = 1;
 
112
count(*)
 
113
1
 
114
select count(*) from t1 where a = 100;
 
115
count(*)
 
116
0
 
117
select count(*) from t1 where a >= 10;
 
118
count(*)
 
119
0
 
120
select count(a) from t1 where a = 1;
 
121
count(a)
 
122
1
 
123
select count(a) from t1 where a = 100;
 
124
count(a)
 
125
0
 
126
select count(a) from t1 where a >= 10;
 
127
count(a)
 
128
0
 
129
select count(b) from t1 where b >= 2;
 
130
count(b)
 
131
2
 
132
select count(b) from t1 where b >= 10;
 
133
count(b)
 
134
0
 
135
select count(c) from t1 where c = 10;
 
136
count(c)
 
137
0
 
138
drop table t1;
 
139
CREATE TABLE t1 (d DATETIME, i INT);
 
140
INSERT INTO t1 VALUES (NOW(), 1);
 
141
SELECT COUNT(i), i, COUNT(i)*i FROM t1 GROUP BY i;
 
142
COUNT(i)        i       COUNT(i)*i 
 
143
1       1       1
 
144
SELECT COUNT(i), (i+0), COUNT(i)*(i+0) FROM t1 GROUP BY i;
 
145
COUNT(i)        (i+0)   COUNT(i)*(i+0)
 
146
1       1       1
 
147
DROP TABLE t1;
 
148
create table t1 (
 
149
num float(5,2),
 
150
user char(20)
 
151
);
 
152
insert into t1 values (10.3,'nem'),(20.53,'monty'),(30.23,'sinisa');
 
153
insert into t1 values (30.13,'nem'),(20.98,'monty'),(10.45,'sinisa');
 
154
insert into t1 values (5.2,'nem'),(8.64,'monty'),(11.12,'sinisa');
 
155
select sum(num) from t1;
 
156
sum(num)
 
157
147.58
 
158
select sum(num) from t1 group by user;
 
159
sum(num)
 
160
50.15
 
161
45.63
 
162
51.80
 
163
drop table t1;
 
164
create table t1 (a1 int, a2 char(3), key k1(a1), key k2(a2));
 
165
insert into t1 values(10,'aaa'), (10,null), (10,'bbb'), (20,'zzz');
 
166
create table t2(a1 char(3), a2 int, a3 real, key k1(a1), key k2(a2, a1));
 
167
select * from t1;
 
168
a1      a2
 
169
10      aaa
 
170
10      NULL
 
171
10      bbb
 
172
20      zzz
 
173
select min(a2) from t1;
 
174
min(a2)
 
175
aaa
 
176
select max(t1.a1), max(t2.a2) from t1, t2;
 
177
max(t1.a1)      max(t2.a2)
 
178
NULL    NULL
 
179
select max(t1.a1) from t1, t2;
 
180
max(t1.a1)
 
181
NULL
 
182
select max(t2.a2), max(t1.a1) from t1, t2;
 
183
max(t2.a2)      max(t1.a1)
 
184
NULL    NULL
 
185
explain select min(a2) from t1;
 
186
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
187
1       SIMPLE  t1      ALL     NULL    NULL    NULL    NULL    4       
 
188
explain select max(t1.a1), max(t2.a2) from t1, t2;
 
189
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
190
1       SIMPLE  t2      ALL     NULL    NULL    NULL    NULL    0       
 
191
1       SIMPLE  t1      ALL     NULL    NULL    NULL    NULL    4       Using join buffer
 
192
insert into t2 values('AAA', 10, 0.5);
 
193
insert into t2 values('BBB', 20, 1.0);
 
194
select t1.a1, t1.a2, t2.a1, t2.a2 from t1,t2;
 
195
a1      a2      a1      a2
 
196
10      NULL    AAA     10
 
197
10      NULL    BBB     20
 
198
10      aaa     AAA     10
 
199
10      aaa     BBB     20
 
200
10      bbb     AAA     10
 
201
10      bbb     BBB     20
 
202
20      zzz     AAA     10
 
203
20      zzz     BBB     20
 
204
select max(t1.a1), max(t2.a1) from t1, t2 where t2.a2=9;
 
205
max(t1.a1)      max(t2.a1)
 
206
NULL    NULL
 
207
select max(t2.a1), max(t1.a1) from t1, t2 where t2.a2=9;
 
208
max(t2.a1)      max(t1.a1)
 
209
NULL    NULL
 
210
select t1.a1, t1.a2, t2.a1, t2.a2 from t1 left outer join t2 on t1.a1=10;
 
211
a1      a2      a1      a2
 
212
10      aaa     AAA     10
 
213
10      aaa     BBB     20
 
214
10      NULL    AAA     10
 
215
10      NULL    BBB     20
 
216
10      bbb     AAA     10
 
217
10      bbb     BBB     20
 
218
20      zzz     NULL    NULL
 
219
select max(t1.a2) from t1 left outer join t2 on t1.a1=10;
 
220
max(t1.a2)
 
221
zzz
 
222
select max(t2.a1) from t2 left outer join t1 on t2.a2=10 where t2.a2=20;
 
223
max(t2.a1)
 
224
BBB
 
225
select max(t2.a1) from t2 left outer join t1 on t2.a2=10 where t2.a2=10;
 
226
max(t2.a1)
 
227
AAA
 
228
select max(t2.a1) from t1 left outer join t2 on t1.a2=t2.a1 and 1=0 where t2.a1='AAA';
 
229
max(t2.a1)
 
230
NULL
 
231
select max(t1.a2),max(t2.a1) from t1 left outer join t2 on t1.a1=10;
 
232
max(t1.a2)      max(t2.a1)
 
233
zzz     BBB
 
234
drop table t1,t2;
 
235
create table t1 (a int);
 
236
select avg(2) from t1;
 
237
avg(2)
 
238
NULL
 
239
drop table t1;
 
240
create table t1(
 
241
a1 char(3) primary key,
 
242
a2 int,
 
243
a3 char(3),
 
244
a4 real,
 
245
a5 date,
 
246
key k1(a2,a3),
 
247
key k2(a4 desc,a1),
 
248
key k3(a5,a1)
 
249
);
 
250
create table t2(
 
251
a1 char(3) primary key,
 
252
a2 char(17),
 
253
a3 char(2),
 
254
a4 char(3),
 
255
key k1(a3, a2),
 
256
key k2(a4)
 
257
);
 
258
insert into t1 values('AME',0,'SEA',0.100,date'1942-02-19');
 
259
insert into t1 values('HBR',1,'SEA',0.085,date'1948-03-05');
 
260
insert into t1 values('BOT',2,'SEA',0.085,date'1951-11-29');
 
261
insert into t1 values('BMC',3,'SEA',0.085,date'1958-09-08');
 
262
insert into t1 values('TWU',0,'LAX',0.080,date'1969-10-05');
 
263
insert into t1 values('BDL',0,'DEN',0.080,date'1960-11-27');
 
264
insert into t1 values('DTX',1,'NYC',0.080,date'1961-05-04');
 
265
insert into t1 values('PLS',1,'WDC',0.075,date'1949-01-02');
 
266
insert into t1 values('ZAJ',2,'CHI',0.075,date'1960-06-15');
 
267
insert into t1 values('VVV',2,'MIN',0.075,date'1959-06-28');
 
268
insert into t1 values('GTM',3,'DAL',0.070,date'1977-09-23');
 
269
insert into t1 values('SSJ',null,'CHI',null,date'1974-03-19');
 
270
insert into t1 values('KKK',3,'ATL',null,null);
 
271
insert into t1 values('XXX',null,'MIN',null,null);
 
272
insert into t1 values('WWW',1,'LED',null,null);
 
273
insert into t2 values('TKF','Seattle','WA','AME');
 
274
insert into t2 values('LCC','Los Angeles','CA','TWU');
 
275
insert into t2 values('DEN','Denver','CO','BDL');
 
276
insert into t2 values('SDC','San Diego','CA','TWU');
 
277
insert into t2 values('NOL','New Orleans','LA','GTM');
 
278
insert into t2 values('LAK','Los Angeles','CA','TWU');
 
279
insert into t2 values('AAA','AAA','AA','AME');
 
280
select * from t1;
 
281
a1      a2      a3      a4      a5
 
282
AME     0       SEA     0.1     1942-02-19
 
283
BDL     0       DEN     0.08    1960-11-27
 
284
BMC     3       SEA     0.085   1958-09-08
 
285
BOT     2       SEA     0.085   1951-11-29
 
286
DTX     1       NYC     0.08    1961-05-04
 
287
GTM     3       DAL     0.07    1977-09-23
 
288
HBR     1       SEA     0.085   1948-03-05
 
289
KKK     3       ATL     NULL    NULL
 
290
PLS     1       WDC     0.075   1949-01-02
 
291
SSJ     NULL    CHI     NULL    1974-03-19
 
292
TWU     0       LAX     0.08    1969-10-05
 
293
VVV     2       MIN     0.075   1959-06-28
 
294
WWW     1       LED     NULL    NULL
 
295
XXX     NULL    MIN     NULL    NULL
 
296
ZAJ     2       CHI     0.075   1960-06-15
 
297
select * from t2;
 
298
a1      a2      a3      a4
 
299
AAA     AAA     AA      AME
 
300
DEN     Denver  CO      BDL
 
301
LAK     Los Angeles     CA      TWU
 
302
LCC     Los Angeles     CA      TWU
 
303
NOL     New Orleans     LA      GTM
 
304
SDC     San Diego       CA      TWU
 
305
TKF     Seattle WA      AME
 
306
explain 
 
307
select min(a1) from t1;
 
308
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
309
1       SIMPLE  t1      ALL     NULL    NULL    NULL    NULL    15      
 
310
select min(a1) from t1;
 
311
min(a1)
 
312
AME
 
313
explain 
 
314
select max(a4) from t1;
 
315
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
316
1       SIMPLE  t1      ALL     NULL    NULL    NULL    NULL    15      
 
317
select max(a4) from t1;
 
318
max(a4)
 
319
0.1
 
320
explain 
 
321
select min(a5), max(a5) from t1;
 
322
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
323
1       SIMPLE  t1      ALL     NULL    NULL    NULL    NULL    15      
 
324
select min(a5), max(a5) from t1;
 
325
min(a5) max(a5)
 
326
1942-02-19      1977-09-23
 
327
explain 
 
328
select min(a3) from t1 where a2 = 2;
 
329
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
330
1       SIMPLE  t1      ref     k1      k1      5       const   1       Using where
 
331
select min(a3) from t1 where a2 = 2;
 
332
min(a3)
 
333
CHI
 
334
explain 
 
335
select min(a1), max(a1) from t1 where a4 = 0.080;
 
336
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
337
1       SIMPLE  t1      ref     k2      k2      9       const   1       Using where
 
338
select min(a1), max(a1) from t1 where a4 = 0.080;
 
339
min(a1) max(a1)
 
340
BDL     TWU
 
341
explain 
 
342
select min(t1.a5), max(t2.a3) from t1, t2;
 
343
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
344
1       SIMPLE  t2      ALL     NULL    NULL    NULL    NULL    7       
 
345
1       SIMPLE  t1      ALL     NULL    NULL    NULL    NULL    15      Using join buffer
 
346
select min(t1.a5), max(t2.a3) from t1, t2;
 
347
min(t1.a5)      max(t2.a3)
 
348
1942-02-19      WA
 
349
explain 
 
350
select min(t1.a3), max(t2.a2) from t1, t2 where t1.a2 = 0 and t2.a3 = 'CA';
 
351
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
352
1       SIMPLE  t1      ref     k1      k1      5       const   1       Using where
 
353
1       SIMPLE  t2      ref     k1      k1      11      const   1       Using where
 
354
select min(t1.a3), max(t2.a2) from t1, t2 where t1.a2 = 0 and t2.a3 = 'CA';
 
355
min(t1.a3)      max(t2.a2)
 
356
DEN     San Diego
 
357
explain 
 
358
select min(a1) from t1 where a1 > 'KKK';
 
359
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
360
1       SIMPLE  t1      ALL     PRIMARY NULL    NULL    NULL    15      Using where
 
361
select min(a1) from t1 where a1 > 'KKK';
 
362
min(a1)
 
363
PLS
 
364
explain 
 
365
select min(a1) from t1 where a1 >= 'KKK';
 
366
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
367
1       SIMPLE  t1      ALL     PRIMARY NULL    NULL    NULL    15      Using where
 
368
select min(a1) from t1 where a1 >= 'KKK';
 
369
min(a1)
 
370
KKK
 
371
explain 
 
372
select max(a3) from t1 where a2 = 2 and a3 < 'SEA';
 
373
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
374
1       SIMPLE  t1      ref     k1      k1      5       const   1       Using where
 
375
select max(a3) from t1 where a2 = 2 and a3 < 'SEA';
 
376
max(a3)
 
377
MIN
 
378
explain 
 
379
select max(a5) from t1 where a5 < date'1970-01-01';
 
380
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
381
1       SIMPLE  t1      ALL     k3      NULL    NULL    NULL    15      Using where
 
382
select max(a5) from t1 where a5 < date'1970-01-01';
 
383
max(a5)
 
384
1969-10-05
 
385
explain 
 
386
select max(a3) from t1 where a2 is null;
 
387
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
388
1       SIMPLE  t1      ref     k1      k1      5       const   1       Using where
 
389
select max(a3) from t1 where a2 is null;
 
390
max(a3)
 
391
MIN
 
392
explain 
 
393
select max(a3) from t1 where a2 = 0 and a3 between 'K' and 'Q';
 
394
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
395
1       SIMPLE  t1      ref     k1      k1      5       const   1       Using where
 
396
select max(a3) from t1 where a2 = 0 and a3 between 'K' and 'Q';
 
397
max(a3)
 
398
LAX
 
399
explain
 
400
select min(a1), max(a1) from t1 where a1 between 'A' and 'P';
 
401
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
402
1       SIMPLE  t1      ALL     PRIMARY NULL    NULL    NULL    15      Using where
 
403
select min(a1), max(a1) from t1 where a1 between 'A' and 'P';
 
404
min(a1) max(a1)
 
405
AME     KKK
 
406
explain 
 
407
select max(a3) from t1 where a3 < 'SEA' and a2 = 2 and a3 <= 'MIN';
 
408
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
409
1       SIMPLE  t1      ref     k1      k1      5       const   1       Using where
 
410
select max(a3) from t1 where a3 < 'SEA' and a2 = 2 and a3 <= 'MIN';
 
411
max(a3)
 
412
MIN
 
413
explain 
 
414
select max(a3) from t1 where a3 = 'MIN' and a2 = 2;
 
415
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
416
1       SIMPLE  t1      ref     k1      k1      20      const,const     1       Using where
 
417
select max(a3) from t1 where a3 = 'MIN' and a2 = 2;
 
418
max(a3)
 
419
MIN
 
420
explain 
 
421
select max(a3) from t1 where a3 = 'DEN' and a2 = 2;
 
422
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
423
1       SIMPLE  t1      ref     k1      k1      20      const,const     1       Using where
 
424
select max(a3) from t1 where a3 = 'DEN' and a2 = 2;
 
425
max(a3)
 
426
NULL
 
427
explain
 
428
select max(t1.a3), min(t2.a2) from t1, t2 where t1.a2 = 2 and t1.a3 < 'MIN' and t2.a3 = 'CA';
 
429
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
430
1       SIMPLE  t1      ref     k1      k1      5       const   1       Using where
 
431
1       SIMPLE  t2      ref     k1      k1      11      const   1       Using where
 
432
select max(t1.a3), min(t2.a2) from t1, t2 where t1.a2 = 2 and t1.a3 < 'MIN' and t2.a3 = 'CA';
 
433
max(t1.a3)      min(t2.a2)
 
434
CHI     Los Angeles
 
435
explain
 
436
select max(a3) from t1 where a2 is null and a2 = 2;
 
437
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
438
1       SIMPLE  NULL    NULL    NULL    NULL    NULL    NULL    NULL    Impossible WHERE
 
439
select max(a3) from t1 where a2 is null and a2 = 2;
 
440
max(a3)
 
441
NULL
 
442
explain
 
443
select max(a2) from t1 where a2 >= 1;
 
444
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
445
1       SIMPLE  t1      ALL     k1      NULL    NULL    NULL    15      Using where
 
446
select max(a2) from t1 where a2 >= 1;
 
447
max(a2)
 
448
3
 
449
explain
 
450
select min(a3) from t1 where a2 = 2 and a3 < 'SEA';
 
451
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
452
1       SIMPLE  t1      ref     k1      k1      5       const   1       Using where
 
453
select min(a3) from t1 where a2 = 2 and a3 < 'SEA';
 
454
min(a3)
 
455
CHI
 
456
explain
 
457
select min(a3) from t1 where a2 = 4;
 
458
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
459
1       SIMPLE  t1      ref     k1      k1      5       const   1       Using where
 
460
select min(a3) from t1 where a2 = 4;
 
461
min(a3)
 
462
NULL
 
463
explain
 
464
select min(a3) from t1 where a2 = 2 and a3 > 'SEA';
 
465
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
466
1       SIMPLE  t1      ref     k1      k1      5       const   1       Using where
 
467
select min(a3) from t1 where a2 = 2 and a3 > 'SEA';
 
468
min(a3)
 
469
NULL
 
470
explain
 
471
select (min(a4)+max(a4))/2 from t1;
 
472
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
473
1       SIMPLE  t1      ALL     NULL    NULL    NULL    NULL    15      
 
474
select (min(a4)+max(a4))/2 from t1;
 
475
(min(a4)+max(a4))/2
 
476
0.085
 
477
explain
 
478
select min(a3) from t1 where 2 = a2;
 
479
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
480
1       SIMPLE  t1      ref     k1      k1      5       const   1       Using where
 
481
select min(a3) from t1 where 2 = a2;
 
482
min(a3)
 
483
CHI
 
484
explain
 
485
select max(a3) from t1 where a2 = 2 and 'SEA' > a3;
 
486
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
487
1       SIMPLE  t1      ref     k1      k1      5       const   1       Using where
 
488
select max(a3) from t1 where a2 = 2 and 'SEA' > a3;
 
489
max(a3)
 
490
MIN
 
491
explain
 
492
select max(a3) from t1 where a2 = 2 and 'SEA' < a3;
 
493
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
494
1       SIMPLE  t1      ref     k1      k1      5       const   1       Using where
 
495
select max(a3) from t1 where a2 = 2 and 'SEA' < a3;
 
496
max(a3)
 
497
NULL
 
498
explain
 
499
select min(a3) from t1 where a2 = 2 and a3 >= 'CHI';
 
500
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
501
1       SIMPLE  t1      ref     k1      k1      5       const   1       Using where
 
502
select min(a3) from t1 where a2 = 2 and a3 >= 'CHI';
 
503
min(a3)
 
504
CHI
 
505
explain
 
506
select min(a3) from t1 where a2 = 2 and a3 >= 'CHI' and a3 < 'SEA';
 
507
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
508
1       SIMPLE  t1      ref     k1      k1      5       const   1       Using where
 
509
select min(a3) from t1 where a2 = 2 and a3 >= 'CHI' and a3 < 'SEA';
 
510
min(a3)
 
511
CHI
 
512
explain
 
513
select min(a3) from t1 where a2 = 2 and a3 >= 'CHI' and a3 = 'MIN';
 
514
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
515
1       SIMPLE  t1      ref     k1      k1      20      const,const     1       Using where
 
516
select min(a3) from t1 where a2 = 2 and a3 >= 'CHI' and a3 = 'MIN';
 
517
min(a3)
 
518
MIN
 
519
explain
 
520
select min(a3) from t1 where a2 = 2 and a3 >= 'SEA' and a3 = 'MIN';
 
521
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
522
1       SIMPLE  NULL    NULL    NULL    NULL    NULL    NULL    NULL    Impossible WHERE
 
523
select min(a3) from t1 where a2 = 2 and a3 >= 'SEA' and a3 = 'MIN';
 
524
min(a3)
 
525
NULL
 
526
explain
 
527
select min(t1.a1), min(t2.a4) from t1,t2 where t1.a1 < 'KKK' and t2.a4 < 'KKK';
 
528
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
529
1       SIMPLE  t2      ALL     k2      NULL    NULL    NULL    7       Using where
 
530
1       SIMPLE  t1      ALL     PRIMARY NULL    NULL    NULL    15      Using where; Using join buffer
 
531
select min(t1.a1), min(t2.a4) from t1,t2 where t1.a1 < 'KKK' and t2.a4 < 'KKK';
 
532
min(t1.a1)      min(t2.a4)
 
533
AME     AME
 
534
explain 
 
535
select min(a1) from t1 where a1 > 'KKK' or a1 < 'XXX';
 
536
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
537
1       SIMPLE  t1      ALL     PRIMARY NULL    NULL    NULL    15      Using where
 
538
explain 
 
539
select min(a1) from t1 where a1 != 'KKK';
 
540
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
541
1       SIMPLE  t1      ALL     PRIMARY NULL    NULL    NULL    15      Using where
 
542
explain
 
543
select max(a3) from t1 where a2 < 2 and a3 < 'SEA';
 
544
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
545
1       SIMPLE  t1      ALL     k1      NULL    NULL    NULL    15      Using where
 
546
explain
 
547
select max(t1.a3), min(t2.a2) from t1, t2 where t1.a2 = 2 and t1.a3 < 'MIN' and t2.a3 > 'CA';
 
548
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
549
1       SIMPLE  t1      ref     k1      k1      5       const   1       Using where
 
550
1       SIMPLE  t2      ALL     k1      NULL    NULL    NULL    7       Using where; Using join buffer
 
551
explain
 
552
select min(a4 - 0.01) from t1;
 
553
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
554
1       SIMPLE  t1      ALL     NULL    NULL    NULL    NULL    15      
 
555
explain
 
556
select max(a4 + 0.01) from t1;
 
557
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
558
1       SIMPLE  t1      ALL     NULL    NULL    NULL    NULL    15      
 
559
explain
 
560
select min(a3) from t1 where (a2 +1 ) is null;
 
561
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
562
1       SIMPLE  t1      ALL     NULL    NULL    NULL    NULL    15      Using where
 
563
explain
 
564
select min(a3) from t1 where (a2 + 1) = 2;
 
565
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
566
1       SIMPLE  t1      ALL     NULL    NULL    NULL    NULL    15      Using where
 
567
explain
 
568
select min(a3) from t1 where 2 = (a2 + 1);
 
569
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
570
1       SIMPLE  t1      ALL     NULL    NULL    NULL    NULL    15      Using where
 
571
explain
 
572
select min(a2) from t1 where a2 < 2 * a2 - 8;
 
573
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
574
1       SIMPLE  t1      ALL     NULL    NULL    NULL    NULL    15      Using where
 
575
explain
 
576
select min(a1) from t1  where a1 between a3 and 'KKK';
 
577
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
578
1       SIMPLE  t1      ALL     PRIMARY NULL    NULL    NULL    15      Using where
 
579
explain
 
580
select min(a4) from t1  where (a4 + 0.01) between 0.07 and 0.08;
 
581
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
582
1       SIMPLE  t1      ALL     NULL    NULL    NULL    NULL    15      Using where
 
583
explain
 
584
select concat(min(t1.a1),min(t2.a4)) from t1, t2 where t2.a4 <> 'AME';
 
585
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
586
1       SIMPLE  t2      ALL     k2      NULL    NULL    NULL    7       Using where
 
587
1       SIMPLE  t1      ALL     NULL    NULL    NULL    NULL    15      Using join buffer
 
588
drop table t1, t2;
 
589
create table t1 (a char);
 
590
insert into t1 values ('a'),('b');
 
591
show create table t1;
 
592
Table   Create Table
 
593
t1      CREATE TABLE `t1` (
 
594
  `a` VARCHAR(1) COLLATE utf8_general_ci DEFAULT NULL
 
595
) ENGINE=DEFAULT COLLATE = utf8_general_ci
 
596
create table t2 select max(a),min(a) from t1;
 
597
show create table t2;
 
598
Table   Create Table
 
599
t2      CREATE TABLE `t2` (
 
600
  `max(a)` VARCHAR(1) COLLATE utf8_general_ci DEFAULT NULL,
 
601
  `min(a)` VARCHAR(1) COLLATE utf8_general_ci DEFAULT NULL
 
602
) ENGINE=DEFAULT COLLATE = utf8_general_ci
 
603
drop table t2;
 
604
create table t2 select concat(a) from t1;
 
605
show create table t2;
 
606
Table   Create Table
 
607
t2      CREATE TABLE `t2` (
 
608
  `concat(a)` VARCHAR(1) COLLATE utf8_general_ci DEFAULT NULL
 
609
) ENGINE=DEFAULT COLLATE = utf8_general_ci
 
610
drop table t2,t1;
 
611
create table t1 (a int);
 
612
insert into t1 values (1);
 
613
select max(a) as b from t1 having b=1;
 
614
b
 
615
1
 
616
select a from t1 having a=1;
 
617
a
 
618
1
 
619
drop table t1;
 
620
create table t1 (a int);
 
621
select variance(2) from t1;
 
622
variance(2)
 
623
NULL
 
624
select stddev(2) from t1;
 
625
stddev(2)
 
626
NULL
 
627
drop table t1;
 
628
create table t1 (a int);
 
629
insert into t1 values (1),(2);
 
630
SELECT COUNT(*) FROM t1;
 
631
COUNT(*)
 
632
2
 
633
SELECT COUNT(*) FROM t1;
 
634
COUNT(*)
 
635
2
 
636
SELECT COUNT(*) FROM t1;
 
637
COUNT(*)
 
638
2
 
639
drop table t1;
 
640
create table t1 (a int, primary key(a));
 
641
insert into t1 values (1),(2);
 
642
SELECT max(a) FROM t1;
 
643
max(a)
 
644
2
 
645
SELECT max(a) FROM t1;
 
646
max(a)
 
647
2
 
648
SELECT max(a) FROM t1;
 
649
max(a)
 
650
2
 
651
drop table t1;
 
652
CREATE TABLE t1 (a int primary key);
 
653
INSERT INTO t1 VALUES (1),(2),(3),(4);
 
654
SELECT MAX(a) FROM t1 WHERE a > 5;
 
655
MAX(a)
 
656
NULL
 
657
SELECT MIN(a) FROM t1 WHERE a < 0;
 
658
MIN(a)
 
659
NULL
 
660
DROP TABLE t1;
 
661
CREATE TEMPORARY TABLE t1 (
 
662
id int NOT NULL auto_increment,
 
663
val enum('one','two','three') NOT NULL default 'one',
 
664
PRIMARY KEY  (id)
 
665
) ENGINE=MyISAM;
 
666
INSERT INTO t1 VALUES
 
667
(1,'one'),(2,'two'),(3,'three'),(4,'one'),(5,'two');
 
668
select val, count(*) from t1 group by val;
 
669
val     count(*)
 
670
one     2
 
671
two     2
 
672
three   1
 
673
drop table t1;
 
674
create table t1(a int, b datetime);
 
675
insert into t1 values (1, NOW()), (2, NOW());
 
676
create table t2 select MAX(b) from t1 group by a;
 
677
show create table t2;
 
678
Table   Create Table
 
679
t2      CREATE TABLE `t2` (
 
680
  `MAX(b)` DATETIME DEFAULT NULL
 
681
) ENGINE=DEFAULT COLLATE = utf8_general_ci
 
682
drop table t1, t2;
 
683
create table t1(f1 datetime);
 
684
insert into t1 values (now());
 
685
create table t2 select f2 from (select max(now()) f2 from t1) a;
 
686
show columns from t2;
 
687
Field   Type    Null    Default Default_is_NULL On_Update
 
688
f2      DATETIME        YES             YES     
 
689
drop table t2;
 
690
create table t2 select f2 from (select now() f2 from t1) a;
 
691
show columns from t2;
 
692
Field   Type    Null    Default Default_is_NULL On_Update
 
693
f2      DATETIME        YES             YES     
 
694
drop table t2, t1;
 
695
CREATE TABLE t1(
 
696
id int PRIMARY KEY,
 
697
a  int,
 
698
b  int,
 
699
INDEX i_b_id(a,b,id),
 
700
INDEX i_id(a,id)
 
701
);
 
702
INSERT INTO t1 VALUES 
 
703
(1,1,4), (2,2,1), (3,1,3), (4,2,1), (5,1,1);
 
704
SELECT MAX(id) FROM t1 WHERE id < 3 AND a=2 AND b=6;
 
705
MAX(id)
 
706
NULL
 
707
DROP TABLE t1;
 
708
CREATE TABLE t1(
 
709
id int PRIMARY KEY,
 
710
a  int,
 
711
b  int,
 
712
INDEX i_id(a,id),
 
713
INDEX i_b_id(a,b,id)
 
714
);
 
715
INSERT INTO t1 VALUES 
 
716
(1,1,4), (2,2,1), (3,1,3), (4,2,1), (5,1,1);
 
717
SELECT MAX(id) FROM t1 WHERE id < 3 AND a=2 AND b=6;
 
718
MAX(id)
 
719
NULL
 
720
DROP TABLE t1;
 
721
CREATE TABLE t1 (id int PRIMARY KEY, b char(3), INDEX(b));
 
722
INSERT INTO t1 VALUES (1,'xx'), (2,'aa');
 
723
SELECT * FROM t1;
 
724
id      b
 
725
1       xx
 
726
2       aa
 
727
SELECT MAX(b) FROM t1 WHERE b < 'ppppp';
 
728
MAX(b)
 
729
aa
 
730
SHOW WARNINGS;
 
731
Level   Code    Message
 
732
SELECT MAX(b) FROM t1 WHERE b < 'pp';
 
733
MAX(b)
 
734
aa
 
735
DROP TABLE t1;
 
736
CREATE TABLE t1 (id int PRIMARY KEY, b char(16), INDEX(b(4)));
 
737
INSERT INTO t1 VALUES (1, 'xxxxbbbb'), (2, 'xxxxaaaa');
 
738
SELECT MAX(b) FROM t1;
 
739
MAX(b)
 
740
xxxxbbbb
 
741
EXPLAIN SELECT MAX(b) FROM t1;
 
742
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
743
1       SIMPLE  t1      ALL     NULL    NULL    NULL    NULL    2       
 
744
DROP TABLE t1;
 
745
CREATE TABLE t1 (a INT, b INT);
 
746
INSERT INTO t1 VALUES (1,1),(1,2),(2,3);
 
747
SELECT (SELECT COUNT(DISTINCT t1.b)) FROM t1 GROUP BY t1.a;
 
748
(SELECT COUNT(DISTINCT t1.b))
 
749
2
 
750
1
 
751
SELECT (SELECT COUNT(DISTINCT 12)) FROM t1 GROUP BY t1.a;
 
752
(SELECT COUNT(DISTINCT 12))
 
753
1
 
754
1
 
755
SELECT AVG(2), COUNT(*), COUNT(12),
 
756
COUNT(DISTINCT 12), MIN(2),MAX(2),STD(2), VARIANCE(2),SUM(2),
 
757
GROUP_CONCAT(2),GROUP_CONCAT(DISTINCT 2);
 
758
AVG(2)  COUNT(*)        COUNT(12)       COUNT(DISTINCT 12)      MIN(2)  MAX(2)  STD(2)  VARIANCE(2)     SUM(2)  GROUP_CONCAT(2) GROUP_CONCAT(DISTINCT 2)
 
759
2.00000 1       1       1       2       2       0.00000 0.00000 2       2       2
 
760
DROP TABLE t1;
 
761
create table t2 (ff double);
 
762
insert into t2 values (2.2);
 
763
select cast(sum(distinct ff) as decimal(5,2)) from t2;
 
764
cast(sum(distinct ff) as decimal(5,2))
 
765
2.20
 
766
select sum(distinct ff) from t2;
 
767
sum(distinct ff)
 
768
2.2
 
769
select cast(variance(ff) as decimal(10,3)) from t2;
 
770
cast(variance(ff) as decimal(10,3))
 
771
0.000
 
772
select cast(min(ff) as decimal(5,2)) from t2;
 
773
cast(min(ff) as decimal(5,2))
 
774
2.20
 
775
create table t1 (df decimal(5,1));
 
776
insert into t1 values(1.1);
 
777
insert into t1 values(2.2);
 
778
select sum(distinct df) from t1;
 
779
sum(distinct df)
 
780
3.3
 
781
select min(df) from t1;
 
782
min(df)
 
783
1.1
 
784
select 1e8 * sum(distinct df) from t1;
 
785
1e8 * sum(distinct df)
 
786
330000000
 
787
select 1e8 * min(df) from t1;
 
788
1e8 * min(df)
 
789
110000000
 
790
create table t3 (ifl int);
 
791
insert into t3 values(1), (2);
 
792
select cast(min(ifl) as decimal(5,2)) from t3;
 
793
cast(min(ifl) as decimal(5,2))
 
794
1.00
 
795
drop table t1, t2, t3;
 
796
CREATE TABLE t1 (id int,value1 float(10,2));
 
797
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);
 
798
select id, stddev_pop(value1), var_pop(value1), stddev_samp(value1), var_samp(value1) from t1 group by id;
 
799
id      stddev_pop(value1)      var_pop(value1) stddev_samp(value1)     var_samp(value1)
 
800
1       0.816497        0.666667        1.000000        1.000000
 
801
2       1.118034        1.250000        1.290994        1.666667
 
802
DROP TABLE t1;
 
803
CREATE TABLE t1 (col1 decimal(16,12));
 
804
INSERT INTO t1 VALUES (-5.00000000001),(-5.00000000002),(-5.00000000003),(-5.00000000000),(-5.00000000001),(-5.00000000002);
 
805
insert into t1 select * from t1;
 
806
select col1,count(col1),sum(col1),avg(col1) from t1 group by col1;
 
807
col1    count(col1)     sum(col1)       avg(col1)
 
808
-5.000000000030 2       -10.000000000060        -5.00000000003000000
 
809
-5.000000000020 4       -20.000000000080        -5.00000000002000000
 
810
-5.000000000010 4       -20.000000000040        -5.00000000001000000
 
811
-5.000000000000 2       -10.000000000000        -5.00000000000000000
 
812
DROP TABLE t1;
 
813
create table t1 (col1 decimal(16,12));
 
814
insert into t1 values (-5.00000000001);
 
815
insert into t1 values (-5.00000000001);
 
816
select col1,sum(col1),max(col1),min(col1) from t1 group by col1;
 
817
col1    sum(col1)       max(col1)       min(col1)
 
818
-5.000000000010 -10.000000000020        -5.000000000010 -5.000000000010
 
819
delete from t1;
 
820
insert into t1 values (5.00000000001);
 
821
insert into t1 values (5.00000000001);
 
822
select col1,sum(col1),max(col1),min(col1) from t1 group by col1;
 
823
col1    sum(col1)       max(col1)       min(col1)
 
824
5.000000000010  10.000000000020 5.000000000010  5.000000000010
 
825
DROP TABLE t1;
 
826
CREATE TABLE t1 (a VARCHAR(400));
 
827
INSERT INTO t1 (a) VALUES ("A"), ("a"), ("a "), ("a   "),
 
828
("B"), ("b"), ("b "), ("b   ");
 
829
SELECT COUNT(DISTINCT a) FROM t1;
 
830
COUNT(DISTINCT a)
 
831
2
 
832
DROP TABLE t1;
 
833
CREATE TABLE t1 (a int, b int, c int);
 
834
INSERT INTO t1 (a, b, c) VALUES
 
835
(1,1,1), (1,1,2), (1,1,3),
 
836
(1,2,1), (1,2,2), (1,2,3),
 
837
(1,3,1), (1,3,2), (1,3,3),
 
838
(2,1,1), (2,1,2), (2,1,3),
 
839
(2,2,1), (2,2,2), (2,2,3),
 
840
(2,3,1), (2,3,2), (2,3,3),
 
841
(3,1,1), (3,1,2), (3,1,3),
 
842
(3,2,1), (3,2,2), (3,2,3),
 
843
(3,3,1), (3,3,2), (3,3,3);
 
844
SELECT b/c as v, a FROM t1 ORDER BY v;
 
845
v       a
 
846
0.33333 1
 
847
0.33333 2
 
848
0.33333 3
 
849
0.50000 1
 
850
0.50000 2
 
851
0.50000 3
 
852
0.66667 1
 
853
0.66667 2
 
854
0.66667 3
 
855
1.00000 1
 
856
1.00000 1
 
857
1.00000 1
 
858
1.00000 2
 
859
1.00000 2
 
860
1.00000 2
 
861
1.00000 3
 
862
1.00000 3
 
863
1.00000 3
 
864
1.50000 1
 
865
1.50000 2
 
866
1.50000 3
 
867
2.00000 1
 
868
2.00000 2
 
869
2.00000 3
 
870
3.00000 1
 
871
3.00000 2
 
872
3.00000 3
 
873
SELECT b/c as v, SUM(a) FROM t1 GROUP BY v;
 
874
v       SUM(a)
 
875
0.50000 6
 
876
1.00000 18
 
877
1.50000 6
 
878
2.00000 6
 
879
3.00000 6
 
880
9999999999.99999        12
 
881
SELECT SUM(a) FROM t1 GROUP BY b/c;
 
882
SUM(a)
 
883
6
 
884
18
 
885
6
 
886
6
 
887
6
 
888
12
 
889
DROP TABLE t1;
 
890
set div_precision_increment= @sav_dpi;
 
891
CREATE TABLE t1 (a INT PRIMARY KEY, b INT);
 
892
INSERT INTO t1 VALUES (1,1), (2,2);
 
893
CREATE TABLE t2 (a INT PRIMARY KEY, b INT);
 
894
INSERT INTO t2 VALUES (1,1), (3,3);
 
895
SELECT 
 
896
(SELECT SUM(c.a) FROM t1 ttt, t2 ccc 
 
897
WHERE ttt.a = ccc.b AND ttt.a = t.a GROUP BY ttt.a) AS minid   
 
898
FROM t1 t, t2 c WHERE t.a = c.b;
 
899
minid
 
900
1
 
901
DROP TABLE t1,t2;
 
902
create table t1 select variance(0);
 
903
show create table t1;
 
904
Table   Create Table
 
905
t1      CREATE TABLE `t1` (
 
906
  `variance(0)` DOUBLE(8,4) DEFAULT NULL
 
907
) ENGINE=DEFAULT COLLATE = utf8_general_ci
 
908
drop table t1;
 
909
create table t1 select stddev(0);
 
910
show create table t1;
 
911
Table   Create Table
 
912
t1      CREATE TABLE `t1` (
 
913
  `stddev(0)` DOUBLE(8,4) DEFAULT NULL
 
914
) ENGINE=DEFAULT COLLATE = utf8_general_ci
 
915
drop table t1;
 
916
create table bug22555 (i int primary key auto_increment, s1 int, s2 int, e decimal(30,10), o double);
 
917
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);
 
918
select std(s1/s2) from bug22555 group by i;
 
919
std(s1/s2)
 
920
0.00000000
 
921
0.00000000
 
922
0.00000000
 
923
0.00000000
 
924
0.00000000
 
925
0.00000000
 
926
0.00000000
 
927
0.00000000
 
928
0.00000000
 
929
0.00000000
 
930
select std(e) from bug22555 group by i;
 
931
std(e)
 
932
0.00000000000000
 
933
0.00000000000000
 
934
0.00000000000000
 
935
0.00000000000000
 
936
0.00000000000000
 
937
0.00000000000000
 
938
0.00000000000000
 
939
0.00000000000000
 
940
0.00000000000000
 
941
0.00000000000000
 
942
select std(o) from bug22555 group by i;
 
943
std(o)
 
944
0
 
945
0
 
946
0
 
947
0
 
948
0
 
949
0
 
950
0
 
951
0
 
952
0
 
953
0
 
954
drop table bug22555;
 
955
create table bug22555 (i int, s1 int, s2 int, o1 double, o2 double, e1 decimal, e2 decimal);
 
956
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);
 
957
select i, count(*) from bug22555 group by i;
 
958
i       count(*)
 
959
1       1
 
960
2       1
 
961
3       1
 
962
select std(s1/s2) from bug22555 where i=1;
 
963
std(s1/s2)
 
964
0.00000000
 
965
select std(s1/s2) from bug22555 where i=2;
 
966
std(s1/s2)
 
967
0.00000000
 
968
select std(s1/s2) from bug22555 where i=3;
 
969
std(s1/s2)
 
970
0.00000000
 
971
select std(s1/s2) from bug22555 where i=1 group by i;
 
972
std(s1/s2)
 
973
0.00000000
 
974
select std(s1/s2) from bug22555 where i=2 group by i;
 
975
std(s1/s2)
 
976
0.00000000
 
977
select std(s1/s2) from bug22555 where i=3 group by i;
 
978
std(s1/s2)
 
979
0.00000000
 
980
select std(s1/s2) from bug22555 group by i order by i;
 
981
std(s1/s2)
 
982
0.00000000
 
983
0.00000000
 
984
0.00000000
 
985
select i, count(*), std(o1/o2) from bug22555 group by i order by i;
 
986
i       count(*)        std(o1/o2)
 
987
1       1       0
 
988
2       1       0
 
989
3       1       0
 
990
select i, count(*), std(e1/e2) from bug22555 group by i order by i;
 
991
i       count(*)        std(e1/e2)
 
992
1       1       0.00000000
 
993
2       1       0.00000000
 
994
3       1       0.00000000
 
995
set @saved_div_precision_increment=@@div_precision_increment;
 
996
set div_precision_increment=19;
 
997
select i, count(*), variance(s1/s2) from bug22555 group by i order by i;
 
998
i       count(*)        variance(s1/s2)
 
999
1       1       0.000000000000000000000000000000
 
1000
2       1       0.000000000000000000000000000000
 
1001
3       1       0.000000000000000000000000000000
 
1002
select i, count(*), variance(o1/o2) from bug22555 group by i order by i;
 
1003
i       count(*)        variance(o1/o2)
 
1004
1       1       0
 
1005
2       1       0
 
1006
3       1       0
 
1007
select i, count(*), variance(e1/e2) from bug22555 group by i order by i;
 
1008
i       count(*)        variance(e1/e2)
 
1009
1       1       0.000000000000000000000000000000
 
1010
2       1       0.000000000000000000000000000000
 
1011
3       1       0.000000000000000000000000000000
 
1012
select i, count(*), std(s1/s2) from bug22555 group by i order by i;
 
1013
i       count(*)        std(s1/s2)
 
1014
1       1       0.000000000000000000000000000000
 
1015
2       1       0.000000000000000000000000000000
 
1016
3       1       0.000000000000000000000000000000
 
1017
select i, count(*), std(o1/o2) from bug22555 group by i order by i;
 
1018
i       count(*)        std(o1/o2)
 
1019
1       1       0
 
1020
2       1       0
 
1021
3       1       0
 
1022
select i, count(*), std(e1/e2) from bug22555 group by i order by i;
 
1023
i       count(*)        std(e1/e2)
 
1024
1       1       0.000000000000000000000000000000
 
1025
2       1       0.000000000000000000000000000000
 
1026
3       1       0.000000000000000000000000000000
 
1027
set div_precision_increment=20;
 
1028
select i, count(*), variance(s1/s2) from bug22555 group by i order by i;
 
1029
i       count(*)        variance(s1/s2)
 
1030
1       1       0.000000000000000000000000000000
 
1031
2       1       0.000000000000000000000000000000
 
1032
3       1       0.000000000000000000000000000000
 
1033
select i, count(*), variance(o1/o2) from bug22555 group by i order by i;
 
1034
i       count(*)        variance(o1/o2)
 
1035
1       1       0
 
1036
2       1       0
 
1037
3       1       0
 
1038
select i, count(*), variance(e1/e2) from bug22555 group by i order by i;
 
1039
i       count(*)        variance(e1/e2)
 
1040
1       1       0.000000000000000000000000000000
 
1041
2       1       0.000000000000000000000000000000
 
1042
3       1       0.000000000000000000000000000000
 
1043
select i, count(*), std(s1/s2) from bug22555 group by i order by i;
 
1044
i       count(*)        std(s1/s2)
 
1045
1       1       0.000000000000000000000000000000
 
1046
2       1       0.000000000000000000000000000000
 
1047
3       1       0.000000000000000000000000000000
 
1048
select i, count(*), std(o1/o2) from bug22555 group by i order by i;
 
1049
i       count(*)        std(o1/o2)
 
1050
1       1       0
 
1051
2       1       0
 
1052
3       1       0
 
1053
select i, count(*), std(e1/e2) from bug22555 group by i order by i;
 
1054
i       count(*)        std(e1/e2)
 
1055
1       1       0.000000000000000000000000000000
 
1056
2       1       0.000000000000000000000000000000
 
1057
3       1       0.000000000000000000000000000000
 
1058
set @@div_precision_increment=@saved_div_precision_increment;
 
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
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);
 
1061
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);
 
1062
select i, count(*), std(s1/s2) from bug22555 group by i order by i;
 
1063
i       count(*)        std(s1/s2)
 
1064
1       4       0.00000000
 
1065
2       4       0.00000000
 
1066
3       4       0.00000000
 
1067
select i, count(*), round(std(o1/o2), 16) from bug22555 group by i order by i;
 
1068
i       count(*)        round(std(o1/o2), 16)
 
1069
1       4       0.0000000000000000
 
1070
2       4       0.0000000000000000
 
1071
3       4       0.0000000000000000
 
1072
select i, count(*), std(e1/e2) from bug22555 group by i order by i;
 
1073
i       count(*)        std(e1/e2)
 
1074
1       4       0.00000000
 
1075
2       4       0.00000000
 
1076
3       4       0.00000000
 
1077
select std(s1/s2) from bug22555;
 
1078
std(s1/s2)
 
1079
0.21325764
 
1080
select std(o1/o2) from bug22555;
 
1081
std(o1/o2)
 
1082
0.213257635866493
 
1083
select std(e1/e2) from bug22555;
 
1084
std(e1/e2)
 
1085
0.21325764
 
1086
set @saved_div_precision_increment=@@div_precision_increment;
 
1087
set div_precision_increment=19;
 
1088
select i, count(*), std(s1/s2) from bug22555 group by i order by i;
 
1089
i       count(*)        std(s1/s2)
 
1090
1       4       0.000000000000000000000000000000
 
1091
2       4       0.000000000000000000000000000000
 
1092
3       4       0.000000000000000000000000000000
 
1093
select i, count(*), round(std(o1/o2), 16) from bug22555 group by i order by i;
 
1094
i       count(*)        round(std(o1/o2), 16)
 
1095
1       4       0.0000000000000000
 
1096
2       4       0.0000000000000000
 
1097
3       4       0.0000000000000000
 
1098
select i, count(*), std(e1/e2) from bug22555 group by i order by i;
 
1099
i       count(*)        std(e1/e2)
 
1100
1       4       0.000000000000000000000000000000
 
1101
2       4       0.000000000000000000000000000000
 
1102
3       4       0.000000000000000000000000000000
 
1103
select round(std(s1/s2), 17) from bug22555;
 
1104
round(std(s1/s2), 17)
 
1105
0.21325763586649340
 
1106
select std(o1/o2) from bug22555;
 
1107
std(o1/o2)
 
1108
0.213257635866493
 
1109
select round(std(e1/e2), 17) from bug22555;
 
1110
round(std(e1/e2), 17)
 
1111
0.21325763586649340
 
1112
set div_precision_increment=20;
 
1113
select i, count(*), std(s1/s2) from bug22555 group by i order by i;
 
1114
i       count(*)        std(s1/s2)
 
1115
1       4       0.000000000000000000000000000000
 
1116
2       4       0.000000000000000000000000000000
 
1117
3       4       0.000000000000000000000000000000
 
1118
select i, count(*), round(std(o1/o2), 16) from bug22555 group by i order by i;
 
1119
i       count(*)        round(std(o1/o2), 16)
 
1120
1       4       0.0000000000000000
 
1121
2       4       0.0000000000000000
 
1122
3       4       0.0000000000000000
 
1123
select i, count(*), std(e1/e2) from bug22555 group by i order by i;
 
1124
i       count(*)        std(e1/e2)
 
1125
1       4       0.000000000000000000000000000000
 
1126
2       4       0.000000000000000000000000000000
 
1127
3       4       0.000000000000000000000000000000
 
1128
select round(std(s1/s2), 17) from bug22555;
 
1129
round(std(s1/s2), 17)
 
1130
0.21325763586649340
 
1131
select std(o1/o2) from bug22555;
 
1132
std(o1/o2)
 
1133
0.213257635866493
 
1134
select round(std(e1/e2), 17) from bug22555;
 
1135
round(std(e1/e2), 17)
 
1136
0.21325763586649340
 
1137
set @@div_precision_increment=@saved_div_precision_increment;
 
1138
drop table bug22555;
 
1139
create table bug22555 (s int, o double, e decimal);
 
1140
insert into bug22555 values (1,1,1),(2,2,2),(3,3,3),(6,6,6),(7,7,7);
 
1141
select var_samp(s), var_pop(s) from bug22555;
 
1142
var_samp(s)     var_pop(s)
 
1143
6.7000  5.3600
 
1144
select var_samp(o), var_pop(o) from bug22555;
 
1145
var_samp(o)     var_pop(o)
 
1146
6.7     5.36
 
1147
select var_samp(e), var_pop(e) from bug22555;
 
1148
var_samp(e)     var_pop(e)
 
1149
6.7000  5.3600
 
1150
drop table bug22555;
 
1151
create table bug22555 (s int, o double, e decimal);
 
1152
insert into bug22555 values (null,null,null),(null,null,null);
 
1153
select var_samp(s) as 'null', var_pop(s) as 'null' from bug22555;
 
1154
null    null
 
1155
NULL    NULL
 
1156
select var_samp(o) as 'null', var_pop(o) as 'null' from bug22555;
 
1157
null    null
 
1158
NULL    NULL
 
1159
select var_samp(e) as 'null', var_pop(e) as 'null' from bug22555;
 
1160
null    null
 
1161
NULL    NULL
 
1162
insert into bug22555 values (1,1,1);
 
1163
select var_samp(s) as 'null', var_pop(s) as '0' from bug22555;
 
1164
null    0
 
1165
NULL    0.0000
 
1166
select var_samp(o) as 'null', var_pop(o) as '0' from bug22555;
 
1167
null    0
 
1168
NULL    0
 
1169
select var_samp(e) as 'null', var_pop(e) as '0' from bug22555;
 
1170
null    0
 
1171
NULL    0.0000
 
1172
insert into bug22555 values (2,2,2);
 
1173
select var_samp(s) as '0.5', var_pop(s) as '0.25' from bug22555;
 
1174
0.5     0.25
 
1175
0.5000  0.2500
 
1176
select var_samp(o) as '0.5', var_pop(o) as '0.25' from bug22555;
 
1177
0.5     0.25
 
1178
0.5     0.25
 
1179
select var_samp(e) as '0.5', var_pop(e) as '0.25' from bug22555;
 
1180
0.5     0.25
 
1181
0.5000  0.2500
 
1182
drop table bug22555;
 
1183
create table t1 (a decimal(20));
 
1184
insert into t1 values (12345678901234567890);
 
1185
select count(a) from t1;
 
1186
count(a)
 
1187
1
 
1188
select count(distinct a) from t1;
 
1189
count(distinct a)
 
1190
1
 
1191
drop table t1;
 
1192
CREATE TABLE t1 (a INT, b INT);
 
1193
INSERT INTO t1 VALUES (1,1),(1,2),(1,3),(1,4),(1,5),(1,6),(1,7),(1,8);
 
1194
INSERT INTO t1 SELECT a, b+8       FROM t1;
 
1195
INSERT INTO t1 SELECT a, b+16      FROM t1;
 
1196
INSERT INTO t1 SELECT a, b+32      FROM t1;
 
1197
INSERT INTO t1 SELECT a, b+64      FROM t1;
 
1198
INSERT INTO t1 SELECT a, b+128     FROM t1;
 
1199
INSERT INTO t1 SELECT a, b+256     FROM t1;
 
1200
INSERT INTO t1 SELECT a, b+512     FROM t1;
 
1201
INSERT INTO t1 SELECT a, b+1024    FROM t1;
 
1202
INSERT INTO t1 SELECT a, b+2048    FROM t1;
 
1203
INSERT INTO t1 SELECT a, b+4096    FROM t1;
 
1204
INSERT INTO t1 SELECT a, b+8192    FROM t1;
 
1205
INSERT INTO t1 SELECT a, b+16384   FROM t1;
 
1206
INSERT INTO t1 SELECT a, b+32768   FROM t1;
 
1207
SELECT a,COUNT(DISTINCT b) AS cnt FROM t1 GROUP BY a HAVING cnt > 50;
 
1208
a       cnt
 
1209
1       65536
 
1210
SELECT a,SUM(DISTINCT b) AS sumation FROM t1 GROUP BY a HAVING sumation > 50;
 
1211
a       sumation
 
1212
1       2147516416
 
1213
SELECT a,AVG(DISTINCT b) AS average FROM t1 GROUP BY a HAVING average > 50;
 
1214
a       average
 
1215
1       32768.5000
 
1216
DROP TABLE t1;
 
1217
CREATE TABLE t1 ( a INT, b INT, KEY(a) );
 
1218
INSERT INTO t1 VALUES (NULL, 1), (NULL, 2);
 
1219
EXPLAIN SELECT MIN(a), MIN(b) FROM t1;
 
1220
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
1221
1       SIMPLE  t1      ALL     NULL    NULL    NULL    NULL    2       
 
1222
SELECT MIN(a), MIN(b) FROM t1;
 
1223
MIN(a)  MIN(b)
 
1224
NULL    1
 
1225
CREATE TABLE t2( a INT, b INT, c INT, KEY(a, b) );
 
1226
INSERT INTO t2 ( a, b, c ) VALUES ( 1, NULL, 2 ), ( 1, 3, 4 ), ( 1, 4, 4 );
 
1227
EXPLAIN SELECT MIN(b), MIN(c) FROM t2 WHERE a = 1;
 
1228
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
1229
1       SIMPLE  t2      ref     a       a       5       const   1       Using where
 
1230
SELECT MIN(b), MIN(c) FROM t2 WHERE a = 1;
 
1231
MIN(b)  MIN(c)
 
1232
3       2
 
1233
CREATE TABLE t3 (a INT, b INT, c int, KEY(a, b));
 
1234
INSERT INTO t3 VALUES (1, NULL, 1), (2, NULL, 2),  (2, NULL, 2),  (3, NULL, 3);
 
1235
EXPLAIN SELECT MIN(a), MIN(b) FROM t3 where a = 2;
 
1236
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
1237
1       SIMPLE  t3      ref     a       a       5       const   1       Using where
 
1238
SELECT MIN(a), MIN(b) FROM t3 where a = 2;
 
1239
MIN(a)  MIN(b)
 
1240
2       NULL
 
1241
CREATE TABLE t4 (a INT, b INT, c int, KEY(a, b));
 
1242
INSERT INTO t4 VALUES (1, 1, 1), (2, NULL, 2),  (2, NULL, 2),  (3, 1, 3);
 
1243
EXPLAIN SELECT MIN(a), MIN(b) FROM t4 where a = 2;
 
1244
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
1245
1       SIMPLE  t4      ref     a       a       5       const   1       Using where
 
1246
SELECT MIN(a), MIN(b) FROM t4 where a = 2;
 
1247
MIN(a)  MIN(b)
 
1248
2       NULL
 
1249
SELECT MIN(b), min(c) FROM t4 where a = 2;
 
1250
MIN(b)  min(c)
 
1251
NULL    2
 
1252
CREATE TABLE t5( a INT, b INT, KEY( a, b) );
 
1253
INSERT INTO t5 VALUES( 1, 1 ), ( 1, 2 );
 
1254
EXPLAIN SELECT MIN(a), MIN(b) FROM t5 WHERE a = 1;
 
1255
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
1256
1       SIMPLE  t5      ref     a       a       5       const   1       Using where
 
1257
SELECT MIN(a), MIN(b) FROM t5 WHERE a = 1;
 
1258
MIN(a)  MIN(b)
 
1259
1       1
 
1260
SELECT MIN(a), MIN(b) FROM t5 WHERE a = 1 and b > 1;
 
1261
MIN(a)  MIN(b)
 
1262
1       2
 
1263
DROP TABLE t1, t2, t3, t4, t5;
 
1264
CREATE TABLE t1 (a int, b date NOT NULL, KEY k1 (a,b));
 
1265
SELECT MIN(b) FROM t1 WHERE a=1 AND b>'2007-08-01';
 
1266
MIN(b)
 
1267
NULL
 
1268
DROP TABLE t1;
 
1269
CREATE TABLE t1(a DOUBLE);
 
1270
INSERT INTO t1 VALUES (10), (20);
 
1271
SELECT AVG(a), CAST(AVG(a) AS DECIMAL) FROM t1;
 
1272
AVG(a)  CAST(AVG(a) AS DECIMAL)
 
1273
15      15
 
1274
DROP TABLE t1;
 
1275
End of 5.0 tests