~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/r/func_group.result

  • Committer: Brian Aker
  • Date: 2008-09-04 19:31:00 UTC
  • Revision ID: brian@tangent.org-20080904193100-l849hgghfy4urj43
Changing default character set from this point on.

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