1
drop table if exists t1;
2
select floor(5.5),floor(-5.5);
5
explain extended select floor(5.5),floor(-5.5);
6
id select_type table type possible_keys key key_len ref rows filtered Extra
7
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
9
Note 1003 select floor(5.5) AS `floor(5.5)`,floor(-(5.5)) AS `floor(-5.5)`
10
select ceiling(5.5),ceiling(-5.5);
11
ceiling(5.5) ceiling(-5.5)
13
explain extended select ceiling(5.5),ceiling(-5.5);
14
id select_type table type possible_keys key key_len ref rows filtered Extra
15
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
17
Note 1003 select ceiling(5.5) AS `ceiling(5.5)`,ceiling(-(5.5)) AS `ceiling(-5.5)`
18
select truncate(52.64,1),truncate(52.64,2),truncate(52.64,-1),truncate(52.64,-2), truncate(-52.64,1),truncate(-52.64,-1);
19
truncate(52.64,1) truncate(52.64,2) truncate(52.64,-1) truncate(52.64,-2) truncate(-52.64,1) truncate(-52.64,-1)
20
52.6 52.64 50 0 -52.6 -50
21
explain extended select truncate(52.64,1),truncate(52.64,2),truncate(52.64,-1),truncate(52.64,-2), truncate(-52.64,1),truncate(-52.64,-1);
22
id select_type table type possible_keys key key_len ref rows filtered Extra
23
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
25
Note 1003 select truncate(52.64,1) AS `truncate(52.64,1)`,truncate(52.64,2) AS `truncate(52.64,2)`,truncate(52.64,-(1)) AS `truncate(52.64,-1)`,truncate(52.64,-(2)) AS `truncate(52.64,-2)`,truncate(-(52.64),1) AS `truncate(-52.64,1)`,truncate(-(52.64),-(1)) AS `truncate(-52.64,-1)`
26
select round(5.5),round(-5.5);
27
round(5.5) round(-5.5)
29
explain extended select round(5.5),round(-5.5);
30
id select_type table type possible_keys key key_len ref rows filtered Extra
31
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
33
Note 1003 select round(5.5,0) AS `round(5.5)`,round(-(5.5),0) AS `round(-5.5)`
34
select round(5.64,1),round(5.64,2),round(5.64,-1),round(5.64,-2);
35
round(5.64,1) round(5.64,2) round(5.64,-1) round(5.64,-2)
37
select abs(-10), sign(-5), sign(5), sign(0);
38
abs(-10) sign(-5) sign(5) sign(0)
40
explain extended select abs(-10), sign(-5), sign(5), sign(0);
41
id select_type table type possible_keys key key_len ref rows filtered Extra
42
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
44
Note 1003 select abs(-(10)) AS `abs(-10)`,sign(-(5)) AS `sign(-5)`,sign(5) AS `sign(5)`,sign(0) AS `sign(0)`
45
select log(exp(10)),exp(log(sqrt(10))*2),log(-1),log(NULL),log(1,1),log(3,9),log(-1,2),log(NULL,2);
46
log(exp(10)) exp(log(sqrt(10))*2) log(-1) log(NULL) log(1,1) log(3,9) log(-1,2) log(NULL,2)
47
10 10.000000000000002 NULL NULL NULL 2 NULL NULL
48
explain extended select log(exp(10)),exp(log(sqrt(10))*2),log(-1),log(NULL),log(1,1),log(3,9),log(-1,2),log(NULL,2);
49
id select_type table type possible_keys key key_len ref rows filtered Extra
50
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
52
Note 1003 select log(exp(10)) AS `log(exp(10))`,exp((log(sqrt(10)) * 2)) AS `exp(log(sqrt(10))*2)`,log(-(1)) AS `log(-1)`,log(NULL) AS `log(NULL)`,log(1,1) AS `log(1,1)`,log(3,9) AS `log(3,9)`,log(-(1),2) AS `log(-1,2)`,log(NULL,2) AS `log(NULL,2)`
53
select ln(exp(10)),exp(ln(sqrt(10))*2),ln(-1),ln(0),ln(NULL);
54
ln(exp(10)) exp(ln(sqrt(10))*2) ln(-1) ln(0) ln(NULL)
55
10 10.000000000000002 NULL NULL NULL
56
explain extended select ln(exp(10)),exp(ln(sqrt(10))*2),ln(-1),ln(0),ln(NULL);
57
id select_type table type possible_keys key key_len ref rows filtered Extra
58
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
60
Note 1003 select ln(exp(10)) AS `ln(exp(10))`,exp((ln(sqrt(10)) * 2)) AS `exp(ln(sqrt(10))*2)`,ln(-(1)) AS `ln(-1)`,ln(0) AS `ln(0)`,ln(NULL) AS `ln(NULL)`
61
select log2(8),log2(15),log2(-2),log2(0),log2(NULL);
62
log2(8) log2(15) log2(-2) log2(0) log2(NULL)
63
3 3.9068905956085187 NULL NULL NULL
64
explain extended select log2(8),log2(15),log2(-2),log2(0),log2(NULL);
65
id select_type table type possible_keys key key_len ref rows filtered Extra
66
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
68
Note 1003 select log2(8) AS `log2(8)`,log2(15) AS `log2(15)`,log2(-(2)) AS `log2(-2)`,log2(0) AS `log2(0)`,log2(NULL) AS `log2(NULL)`
69
select log10(100),log10(18),log10(-4),log10(0),log10(NULL);
70
log10(100) log10(18) log10(-4) log10(0) log10(NULL)
71
2 1.255272505103306 NULL NULL NULL
72
explain extended select log10(100),log10(18),log10(-4),log10(0),log10(NULL);
73
id select_type table type possible_keys key key_len ref rows filtered Extra
74
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
76
Note 1003 select log10(100) AS `log10(100)`,log10(18) AS `log10(18)`,log10(-(4)) AS `log10(-4)`,log10(0) AS `log10(0)`,log10(NULL) AS `log10(NULL)`
77
select pow(10,log10(10)),power(2,4);
78
pow(10,log10(10)) power(2,4)
80
explain extended select pow(10,log10(10)),power(2,4);
81
id select_type table type possible_keys key key_len ref rows filtered Extra
82
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
84
Note 1003 select pow(10,log10(10)) AS `pow(10,log10(10))`,pow(2,4) AS `power(2,4)`
85
set @@rand_seed1=10000000,@@rand_seed2=1000000;
86
select rand(999999),rand();
88
0.014231365187309091 0.028870999839968048
89
explain extended select rand(999999),rand();
90
id select_type table type possible_keys key key_len ref rows filtered Extra
91
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
93
Note 1003 select rand(999999) AS `rand(999999)`,rand() AS `rand()`
94
select pi(),format(sin(pi()/2),6),format(cos(pi()/2),6),format(abs(tan(pi())),6),format(cot(1),6),format(asin(1),6),format(acos(0),6),format(atan(1),6);
95
pi() format(sin(pi()/2),6) format(cos(pi()/2),6) format(abs(tan(pi())),6) format(cot(1),6) format(asin(1),6) format(acos(0),6) format(atan(1),6)
96
3.141593 1.000000 0.000000 0.000000 0.642093 1.570796 1.570796 0.785398
97
explain extended select pi(),format(sin(pi()/2),6),format(cos(pi()/2),6),format(abs(tan(pi())),6),format(cot(1),6),format(asin(1),6),format(acos(0),6),format(atan(1),6);
98
id select_type table type possible_keys key key_len ref rows filtered Extra
99
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
101
Note 1003 select pi() AS `pi()`,format(sin((pi() / 2)),6) AS `format(sin(pi()/2),6)`,format(cos((pi() / 2)),6) AS `format(cos(pi()/2),6)`,format(abs(tan(pi())),6) AS `format(abs(tan(pi())),6)`,format((1 / tan(1)),6) AS `format(cot(1),6)`,format(asin(1),6) AS `format(asin(1),6)`,format(acos(0),6) AS `format(acos(0),6)`,format(atan(1),6) AS `format(atan(1),6)`
102
select degrees(pi()),radians(360);
103
degrees(pi()) radians(360)
104
180 6.283185307179586
105
select format(atan(-2, 2), 6);
106
format(atan(-2, 2), 6)
108
select format(atan(pi(), 0), 6);
109
format(atan(pi(), 0), 6)
111
select format(atan2(-2, 2), 6);
112
format(atan2(-2, 2), 6)
114
select format(atan2(pi(), 0), 6);
115
format(atan2(pi(), 0), 6)
123
SELECT ACOS(0.2*5.0);
126
SELECT ACOS(0.5*2.0);
129
SELECT ASIN(0.8+0.2);
132
SELECT ASIN(1.2-0.2);
135
select format(4.55, 1), format(4.551, 1);
136
format(4.55, 1) format(4.551, 1)
138
explain extended select degrees(pi()),radians(360);
139
id select_type table type possible_keys key key_len ref rows filtered Extra
140
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
142
Note 1003 select degrees(pi()) AS `degrees(pi())`,radians(360) AS `radians(360)`
144
ERROR 42S22: Unknown column 'rand' in 'field list'
145
create table t1 (col1 int, col2 decimal(60,30));
146
insert into t1 values(1,1234567890.12345);
147
select format(col2,7) from t1;
149
1,234,567,890.1234500
150
select format(col2,8) from t1;
152
1,234,567,890.12345000
153
insert into t1 values(7,1234567890123456.12345);
154
select format(col2,6) from t1 where col1=7;
156
1,234,567,890,123,456.123450
161
select ceil(0.000000000000000009);
162
ceil(0.000000000000000009)
164
create table t1 select round(1, 6);
165
show create table t1;
167
t1 CREATE TABLE `t1` (
168
`round(1, 6)` int(1) NOT NULL DEFAULT '0'
169
) ENGINE=MyISAM DEFAULT CHARSET=latin1
177
CREATE TABLE t1 (a INT);
178
INSERT INTO t1 VALUES (1),(1),(1),(2);
179
SELECT CAST(RAND(2) * 1000 AS UNSIGNED), CAST(RAND(a) * 1000 AS UNSIGNED)
181
CAST(RAND(2) * 1000 AS UNSIGNED) CAST(RAND(a) * 1000 AS UNSIGNED)
186
SELECT CAST(RAND(2) * 1000 AS UNSIGNED), CAST(RAND(a) * 1000 AS UNSIGNED)
188
CAST(RAND(2) * 1000 AS UNSIGNED) CAST(RAND(a) * 1000 AS UNSIGNED)
192
INSERT INTO t1 VALUES (3);
193
SELECT CAST(RAND(2) * 1000 AS UNSIGNED), CAST(RAND(a) * 1000 AS UNSIGNED)
195
CAST(RAND(2) * 1000 AS UNSIGNED) CAST(RAND(a) * 1000 AS UNSIGNED)
201
SELECT CAST(RAND(2) * 1000 AS UNSIGNED), CAST(RAND(a) * 1000 AS UNSIGNED)
203
CAST(RAND(2) * 1000 AS UNSIGNED) CAST(RAND(a) * 1000 AS UNSIGNED)
208
"SELECT CAST(RAND(2) * 1000 AS UNSIGNED), CAST(RAND(?) * 1000 AS UNSIGNED)
209
FROM t1 WHERE a = 1";
211
EXECUTE stmt USING @var;
212
CAST(RAND(2) * 1000 AS UNSIGNED) CAST(RAND(?) * 1000 AS UNSIGNED)
217
create table t1 (a varchar(90), ts datetime not null, index (a)) engine=innodb default charset=utf8;
218
insert into t1 values ('http://www.foo.com/', now());
219
select a from t1 where a='http://www.foo.com/' order by abs(timediff(ts, 0));
223
set sql_mode='traditional';
228
Error 1365 Division by 0
233
Error 1365 Division by 0
238
Error 1365 Division by 0
243
Error 1365 Division by 0
248
Error 1365 Division by 0
250
select round(111,-10);
253
select round(-5000111000111000155,-1);
254
round(-5000111000111000155,-1)
256
select round(15000111000111000155,-1);
257
round(15000111000111000155,-1)
259
select truncate(-5000111000111000155,-1);
260
truncate(-5000111000111000155,-1)
262
select truncate(15000111000111000155,-1);
263
truncate(15000111000111000155,-1)
267
(f1 varchar(32) not null,
268
f2 smallint(5) unsigned not null,
269
f3 int(10) unsigned not null default '0')
270
engine=myisam default charset=utf8;
271
insert into t1 values ('zombie',0,0),('gold',1,10000),('silver',2,10000);
273
(f1 int(10) unsigned not null,
274
f2 int(10) unsigned not null,
275
f3 smallint(5) unsigned not null)
276
engine=myisam default charset=utf8;
277
insert into t2 values (16777216,16787215,1),(33554432,33564431,2);
278
select format(t2.f2-t2.f1+1,0) from t1,t2
279
where t1.f2 = t2.f3 order by t1.f1;
280
format(t2.f2-t2.f1+1,0)
285
select cast(-2 as unsigned), 18446744073709551614, -2;
286
cast(-2 as unsigned) 18446744073709551614 -2
287
18446744073709551614 18446744073709551614 -2
288
select abs(cast(-2 as unsigned)), abs(18446744073709551614), abs(-2);
289
abs(cast(-2 as unsigned)) abs(18446744073709551614) abs(-2)
290
18446744073709551614 18446744073709551614 2
291
select ceiling(cast(-2 as unsigned)), ceiling(18446744073709551614), ceiling(-2);
292
ceiling(cast(-2 as unsigned)) ceiling(18446744073709551614) ceiling(-2)
293
18446744073709551614 18446744073709551614 -2
294
select floor(cast(-2 as unsigned)), floor(18446744073709551614), floor(-2);
295
floor(cast(-2 as unsigned)) floor(18446744073709551614) floor(-2)
296
18446744073709551614 18446744073709551614 -2
297
select format(cast(-2 as unsigned), 2), format(18446744073709551614, 2), format(-2, 2);
298
format(cast(-2 as unsigned), 2) format(18446744073709551614, 2) format(-2, 2)
299
18,446,744,073,709,551,614.00 18,446,744,073,709,551,614.00 -2.00
300
select sqrt(cast(-2 as unsigned)), sqrt(18446744073709551614), sqrt(-2);
301
sqrt(cast(-2 as unsigned)) sqrt(18446744073709551614) sqrt(-2)
302
4294967296 4294967296 NULL
303
select round(cast(-2 as unsigned), 1), round(18446744073709551614, 1), round(-2, 1);
304
round(cast(-2 as unsigned), 1) round(18446744073709551614, 1) round(-2, 1)
305
18446744073709551614 18446744073709551614 -2
306
select round(4, cast(-2 as unsigned)), round(4, 18446744073709551614), round(4, -2);
307
round(4, cast(-2 as unsigned)) round(4, 18446744073709551614) round(4, -2)
309
select truncate(cast(-2 as unsigned), 1), truncate(18446744073709551614, 1), truncate(-2, 1);
310
truncate(cast(-2 as unsigned), 1) truncate(18446744073709551614, 1) truncate(-2, 1)
311
18446744073709551614 18446744073709551614 -2
312
select truncate(4, cast(-2 as unsigned)), truncate(4, 18446744073709551614), truncate(4, -2);
313
truncate(4, cast(-2 as unsigned)) truncate(4, 18446744073709551614) truncate(4, -2)
315
select round(10000000000000000000, -19), truncate(10000000000000000000, -19);
316
round(10000000000000000000, -19) truncate(10000000000000000000, -19)
317
10000000000000000000 10000000000000000000
318
select round(1e0, -309), truncate(1e0, -309);
319
round(1e0, -309) truncate(1e0, -309)
321
select round(1e1,308), truncate(1e1, 308);
322
round(1e1,308) truncate(1e1, 308)
324
select round(1e1, 2147483648), truncate(1e1, 2147483648);
325
round(1e1, 2147483648) truncate(1e1, 2147483648)
327
select round(1.1e1, 4294967295), truncate(1.1e1, 4294967295);
328
round(1.1e1, 4294967295) truncate(1.1e1, 4294967295)
330
select round(1.12e1, 4294967296), truncate(1.12e1, 4294967296);
331
round(1.12e1, 4294967296) truncate(1.12e1, 4294967296)
333
select round(1.5, 2147483640), truncate(1.5, 2147483640);
334
round(1.5, 2147483640) truncate(1.5, 2147483640)
335
1.500000000000000000000000000000 1.500000000000000000000000000000
336
select round(1.5, -2147483649), round(1.5, 2147483648);
337
round(1.5, -2147483649) round(1.5, 2147483648)
338
0 1.500000000000000000000000000000
339
select truncate(1.5, -2147483649), truncate(1.5, 2147483648);
340
truncate(1.5, -2147483649) truncate(1.5, 2147483648)
341
0 1.500000000000000000000000000000
342
select round(1.5, -4294967296), round(1.5, 4294967296);
343
round(1.5, -4294967296) round(1.5, 4294967296)
344
0 1.500000000000000000000000000000
345
select truncate(1.5, -4294967296), truncate(1.5, 4294967296);
346
truncate(1.5, -4294967296) truncate(1.5, 4294967296)
347
0 1.500000000000000000000000000000
348
select round(1.5, -9223372036854775808), round(1.5, 9223372036854775808);
349
round(1.5, -9223372036854775808) round(1.5, 9223372036854775808)
350
0 1.500000000000000000000000000000
351
select truncate(1.5, -9223372036854775808), truncate(1.5, 9223372036854775808);
352
truncate(1.5, -9223372036854775808) truncate(1.5, 9223372036854775808)
353
0 1.500000000000000000000000000000
354
select round(1.5, 18446744073709551615), truncate(1.5, 18446744073709551615);
355
round(1.5, 18446744073709551615) truncate(1.5, 18446744073709551615)
356
1.500000000000000000000000000000 1.500000000000000000000000000000
357
select round(18446744073709551614, -1), truncate(18446744073709551614, -1);
358
round(18446744073709551614, -1) truncate(18446744073709551614, -1)
359
18446744073709551610 18446744073709551610
360
select round(4, -4294967200), truncate(4, -4294967200);
361
round(4, -4294967200) truncate(4, -4294967200)
363
select mod(cast(-2 as unsigned), 3), mod(18446744073709551614, 3), mod(-2, 3);
364
mod(cast(-2 as unsigned), 3) mod(18446744073709551614, 3) mod(-2, 3)
366
select mod(5, cast(-2 as unsigned)), mod(5, 18446744073709551614), mod(5, -2);
367
mod(5, cast(-2 as unsigned)) mod(5, 18446744073709551614) mod(5, -2)
369
select pow(cast(-2 as unsigned), 5), pow(18446744073709551614, 5), pow(-2, 5);
370
pow(cast(-2 as unsigned), 5) pow(18446744073709551614, 5) pow(-2, 5)
371
2.13598703592091e96 2.13598703592091e96 -32
372
CREATE TABLE t1 (a timestamp, b varchar(20), c bit(1));
373
INSERT INTO t1 VALUES('1998-09-23', 'str1', 1), ('2003-03-25', 'str2', 0);
374
SELECT a DIV 900 y FROM t1 GROUP BY y;
378
SELECT DISTINCT a DIV 900 y FROM t1;
382
SELECT b DIV 900 y FROM t1 GROUP BY y;
385
SELECT c DIV 900 y FROM t1 GROUP BY y;
389
CREATE TABLE t1(a LONGBLOB);
390
INSERT INTO t1 VALUES('1'),('2'),('3');
391
SELECT DISTINCT (a DIV 254576881) FROM t1;
394
SELECT (a DIV 254576881) FROM t1 UNION ALL
395
SELECT (a DIV 254576881) FROM t1;
404
CREATE TABLE t1(a SET('a','b','c'));
405
INSERT INTO t1 VALUES ('a');
406
SELECT a DIV 2 FROM t1 UNION SELECT a DIV 2 FROM t1;
411
SELECT 1e308 + 1e308;
414
SELECT -1e308 - 1e308;
417
SELECT 1e300 * 1e300;
420
SELECT 1e300 / 1e-300;