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
49
Error 1365 Division by 0
50
Error 1365 Division by 0
51
Error 1365 Division by 0
52
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);
53
id select_type table type possible_keys key key_len ref rows filtered Extra
54
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
56
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)`
57
select ln(exp(10)),exp(ln(sqrt(10))*2),ln(-1),ln(0),ln(NULL);
58
ln(exp(10)) exp(ln(sqrt(10))*2) ln(-1) ln(0) ln(NULL)
59
10 10.000000000000002 NULL NULL NULL
61
Error 1365 Division by 0
62
Error 1365 Division by 0
63
explain extended select ln(exp(10)),exp(ln(sqrt(10))*2),ln(-1),ln(0),ln(NULL);
64
id select_type table type possible_keys key key_len ref rows filtered Extra
65
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
67
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)`
68
select log2(8),log2(15),log2(-2),log2(0),log2(NULL);
69
log2(8) log2(15) log2(-2) log2(0) log2(NULL)
70
3 3.9068905956085187 NULL NULL NULL
72
Error 1365 Division by 0
73
Error 1365 Division by 0
74
explain extended select log2(8),log2(15),log2(-2),log2(0),log2(NULL);
75
id select_type table type possible_keys key key_len ref rows filtered Extra
76
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
78
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)`
79
select log10(100),log10(18),log10(-4),log10(0),log10(NULL);
80
log10(100) log10(18) log10(-4) log10(0) log10(NULL)
81
2 1.255272505103306 NULL NULL NULL
83
Error 1365 Division by 0
84
Error 1365 Division by 0
85
explain extended select log10(100),log10(18),log10(-4),log10(0),log10(NULL);
86
id select_type table type possible_keys key key_len ref rows filtered Extra
87
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
89
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)`
90
select pow(10,log10(10)),power(2,4);
91
pow(10,log10(10)) power(2,4)
93
explain extended select pow(10,log10(10)),power(2,4);
94
id select_type table type possible_keys key key_len ref rows filtered Extra
95
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
97
Note 1003 select pow(10,log10(10)) AS `pow(10,log10(10))`,pow(2,4) AS `power(2,4)`
98
set @@rand_seed1=10000000,@@rand_seed2=1000000;
99
select rand(999999),rand();
101
0.014231365187309091 0.028870999839968048
102
explain extended select rand(999999),rand();
103
id select_type table type possible_keys key key_len ref rows filtered Extra
104
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
106
Note 1003 select rand(999999) AS `rand(999999)`,rand() AS `rand()`
107
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);
108
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)
109
3.141593 1.000000 0.000000 0.000000 0.642093 1.570796 1.570796 0.785398
110
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);
111
id select_type table type possible_keys key key_len ref rows filtered Extra
112
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
114
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)`
115
select degrees(pi()),radians(360);
116
degrees(pi()) radians(360)
117
180 6.283185307179586
118
select format(atan(-2, 2), 6);
119
format(atan(-2, 2), 6)
121
select format(atan(pi(), 0), 6);
122
format(atan(pi(), 0), 6)
124
select format(atan2(-2, 2), 6);
125
format(atan2(-2, 2), 6)
127
select format(atan2(pi(), 0), 6);
128
format(atan2(pi(), 0), 6)
136
SELECT ACOS(0.2*5.0);
139
SELECT ACOS(0.5*2.0);
142
SELECT ASIN(0.8+0.2);
145
SELECT ASIN(1.2-0.2);
148
select format(4.55, 1), format(4.551, 1);
149
format(4.55, 1) format(4.551, 1)
151
explain extended select degrees(pi()),radians(360);
152
id select_type table type possible_keys key key_len ref rows filtered Extra
153
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
155
Note 1003 select degrees(pi()) AS `degrees(pi())`,radians(360) AS `radians(360)`
157
ERROR 42S22: Unknown column 'rand' in 'field list'
158
create table t1 (col1 int, col2 decimal(60,30));
159
insert into t1 values(1,1234567890.12345);
160
select format(col2,7) from t1;
162
1,234,567,890.1234500
163
select format(col2,8) from t1;
165
1,234,567,890.12345000
166
insert into t1 values(7,1234567890123456.12345);
167
select format(col2,6) from t1 where col1=7;
169
1,234,567,890,123,456.123450
174
select ceil(0.000000000000000009);
175
ceil(0.000000000000000009)
177
create table t1 select round(1, 6);
178
show create table t1;
180
t1 CREATE TABLE `t1` (
181
`round(1, 6)` int NOT NULL
190
CREATE TABLE t1 (a INT);
191
INSERT INTO t1 VALUES (1),(1),(1),(2);
192
SELECT RAND(2) * 1000, RAND(a) * 1000 FROM t1;
193
RAND(2) * 1000 RAND(a) * 1000
194
655.5866465490186 405.40353712197725
195
122.34661925802624 405.40353712197725
196
644.97318737672 405.40353712197725
197
857.8261098431667 655.5866465490186
198
SELECT RAND(2) * 1000, RAND(a) * 1000 FROM t1 WHERE a = 1;
199
RAND(2) * 1000 RAND(a) * 1000
200
655.5866465490186 405.40353712197725
201
122.34661925802624 405.40353712197725
202
644.97318737672 405.40353712197725
203
INSERT INTO t1 VALUES (3);
204
SELECT RAND(2) * 1000, RAND(a) * 1000 FROM t1;
205
RAND(2) * 1000 RAND(a) * 1000
206
655.5866465490186 405.40353712197725
207
122.34661925802624 405.40353712197725
208
644.97318737672 405.40353712197725
209
857.8261098431667 655.5866465490186
210
354.21101781931804 905.7697559760601
211
SELECT RAND(2) * 1000, RAND(a) * 1000 FROM t1 WHERE a = 1;
212
RAND(2) * 1000 RAND(a) * 1000
213
655.5866465490186 405.40353712197725
214
122.34661925802624 405.40353712197725
215
644.97318737672 405.40353712197725
217
create table t1 (a varchar(90), ts datetime not null, index (a)) engine=innodb;
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
select round(111,-10);
226
select round(-5000111000111000155,-1);
227
round(-5000111000111000155,-1)
229
select round(15000111000111000155,-1);
230
round(15000111000111000155,-1)
232
select truncate(-5000111000111000155,-1);
233
truncate(-5000111000111000155,-1)
235
select truncate(15000111000111000155,-1);
236
truncate(15000111000111000155,-1)
239
(f1 varchar(32) not null,
241
f3 int not null default '0')
243
insert into t1 values ('zombie',0,0),('gold',1,10000),('silver',2,10000);
249
insert into t2 values (16777216,16787215,1),(33554432,33564431,2);
250
select format(t2.f2-t2.f1+1,0) from t1,t2
251
where t1.f2 = t2.f3 order by t1.f1;
252
format(t2.f2-t2.f1+1,0)
256
select -2, 18446744073709551614, -2;
257
-2 18446744073709551614 -2
258
-2 18446744073709551614 -2
259
select abs(-2), abs(18446744073709551614), abs(-2);
260
abs(-2) abs(18446744073709551614) abs(-2)
261
2 18446744073709551614 2
262
select ceiling(-2), ceiling(18446744073709551614), ceiling(-2);
263
ceiling(-2) ceiling(18446744073709551614) ceiling(-2)
264
-2 18446744073709551614 -2
265
select floor(-2), floor(18446744073709551614), floor(-2);
266
floor(-2) floor(18446744073709551614) floor(-2)
267
-2 18446744073709551614 -2
268
select format(-2, 2), format(18446744073709551614, 2), format(-2, 2);
269
format(-2, 2) format(18446744073709551614, 2) format(-2, 2)
270
-2.00 18,446,744,073,709,551,614.00 -2.00
271
select sqrt(-2), sqrt(18446744073709551614), sqrt(-2);
272
sqrt(-2) sqrt(18446744073709551614) sqrt(-2)
274
select round(-2, 1), round(18446744073709551614, 1), round(-2, 1);
275
round(-2, 1) round(18446744073709551614, 1) round(-2, 1)
276
-2 18446744073709551614 -2
277
select round(4, -2), round(4, 18446744073709551614), round(4, -2);
278
round(4, -2) round(4, 18446744073709551614) round(4, -2)
280
select truncate(-2, 1), truncate(18446744073709551614, 1), truncate(-2, 1);
281
truncate(-2, 1) truncate(18446744073709551614, 1) truncate(-2, 1)
282
-2 18446744073709551614 -2
283
select truncate(4, -2), truncate(4, 18446744073709551614), truncate(4, -2);
284
truncate(4, -2) truncate(4, 18446744073709551614) truncate(4, -2)
286
select round(10000000000000000000, -19), truncate(10000000000000000000, -19);
287
round(10000000000000000000, -19) truncate(10000000000000000000, -19)
288
10000000000000000000 10000000000000000000
289
select round(1e0, -309), truncate(1e0, -309);
290
round(1e0, -309) truncate(1e0, -309)
292
select round(1e1,308), truncate(1e1, 308);
293
round(1e1,308) truncate(1e1, 308)
295
select round(1e1, 2147483648), truncate(1e1, 2147483648);
296
round(1e1, 2147483648) truncate(1e1, 2147483648)
298
select round(1.1e1, 4294967295), truncate(1.1e1, 4294967295);
299
round(1.1e1, 4294967295) truncate(1.1e1, 4294967295)
301
select round(1.12e1, 4294967296), truncate(1.12e1, 4294967296);
302
round(1.12e1, 4294967296) truncate(1.12e1, 4294967296)
304
select round(1.5, 2147483640), truncate(1.5, 2147483640);
305
round(1.5, 2147483640) truncate(1.5, 2147483640)
306
1.500000000000000000000000000000 1.500000000000000000000000000000
307
select round(1.5, -2147483649), round(1.5, 2147483648);
308
round(1.5, -2147483649) round(1.5, 2147483648)
309
0 1.500000000000000000000000000000
310
select truncate(1.5, -2147483649), truncate(1.5, 2147483648);
311
truncate(1.5, -2147483649) truncate(1.5, 2147483648)
312
0 1.500000000000000000000000000000
313
select round(1.5, -4294967296), round(1.5, 4294967296);
314
round(1.5, -4294967296) round(1.5, 4294967296)
315
0 1.500000000000000000000000000000
316
select truncate(1.5, -4294967296), truncate(1.5, 4294967296);
317
truncate(1.5, -4294967296) truncate(1.5, 4294967296)
318
0 1.500000000000000000000000000000
319
select round(1.5, -9223372036854775808), round(1.5, 9223372036854775808);
320
round(1.5, -9223372036854775808) round(1.5, 9223372036854775808)
321
0 2.000000000000000000000000000000
322
select truncate(1.5, -9223372036854775808), truncate(1.5, 9223372036854775808);
323
truncate(1.5, -9223372036854775808) truncate(1.5, 9223372036854775808)
324
0 1.000000000000000000000000000000
325
select round(1.5, 18446744073709551615), truncate(1.5, 18446744073709551615);
326
round(1.5, 18446744073709551615) truncate(1.5, 18446744073709551615)
327
0.000000000000000000000000000000 0.000000000000000000000000000000
328
select round(18446744073709551614, -1), truncate(18446744073709551614, -1);
329
round(18446744073709551614, -1) truncate(18446744073709551614, -1)
330
18446744073709551610 18446744073709551610
331
select round(4, -4294967200), truncate(4, -4294967200);
332
round(4, -4294967200) truncate(4, -4294967200)
334
select mod(-2, 3), mod(18446744073709551614, 3), mod(-2, 3);
335
mod(-2, 3) mod(18446744073709551614, 3) mod(-2, 3)
337
select mod(5, -2), mod(5, 18446744073709551614), mod(5, -2);
338
mod(5, -2) mod(5, 18446744073709551614) mod(5, -2)
340
select pow(-2, 5), pow(18446744073709551614, 5), pow(-2, 5);
341
pow(-2, 5) pow(18446744073709551614, 5) pow(-2, 5)
342
-32 2.13598703592091e96 -32
343
CREATE TABLE t1 (a timestamp, b varchar(20), c int);
344
INSERT INTO t1 VALUES('1998-09-23', 'str1', 1), ('2003-03-25', 'str2', 0);
345
SELECT a DIV 900 y FROM t1 GROUP BY y;
349
SELECT DISTINCT a DIV 900 y FROM t1;
353
SELECT b DIV 900 y FROM t1 GROUP BY y;
356
SELECT c DIV 900 y FROM t1 GROUP BY y;
360
CREATE TABLE t1(a LONGBLOB);
361
INSERT INTO t1 VALUES('1'),('2'),('3');
362
SELECT DISTINCT (a DIV 254576881) FROM t1;
365
SELECT (a DIV 254576881) FROM t1 UNION ALL
366
SELECT (a DIV 254576881) FROM t1;
376
SELECT 1e308 + 1e308;
379
SELECT -1e308 - 1e308;
382
SELECT 1e300 * 1e300;
385
SELECT 1e300 / 1e-300;