190
177
CREATE TABLE t1 (a INT);
191
178
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
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)
203
192
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
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;
217
create table t1 (a varchar(90), ts datetime not null, index (a)) engine=innodb default charset=utf8;
218
218
insert into t1 values ('http://www.foo.com/', now());
219
219
select a from t1 where a='http://www.foo.com/' order by abs(timediff(ts, 0));
221
221
http://www.foo.com/
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
223
250
select round(111,-10);
235
262
select truncate(15000111000111000155,-1);
236
263
truncate(15000111000111000155,-1)
237
264
15000111000111000150
239
267
(f1 varchar(32) not null,
241
f3 int not null default '0')
268
f2 smallint(5) unsigned not null,
269
f3 int(10) unsigned not null default '0')
270
engine=myisam default charset=utf8;
243
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;
249
277
insert into t2 values (16777216,16787215,1),(33554432,33564431,2);
250
278
select format(t2.f2-t2.f1+1,0) from t1,t2
251
279
where t1.f2 = t2.f3 order by t1.f1;
255
283
drop table t1, t2;
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)
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)
286
315
select round(10000000000000000000, -19), truncate(10000000000000000000, -19);
287
316
round(10000000000000000000, -19) truncate(10000000000000000000, -19)
288
317
10000000000000000000 10000000000000000000
318
347
0 1.500000000000000000000000000000
319
348
select round(1.5, -9223372036854775808), round(1.5, 9223372036854775808);
320
349
round(1.5, -9223372036854775808) round(1.5, 9223372036854775808)
321
0 2.000000000000000000000000000000
350
0 1.500000000000000000000000000000
322
351
select truncate(1.5, -9223372036854775808), truncate(1.5, 9223372036854775808);
323
352
truncate(1.5, -9223372036854775808) truncate(1.5, 9223372036854775808)
324
0 1.000000000000000000000000000000
353
0 1.500000000000000000000000000000
325
354
select round(1.5, 18446744073709551615), truncate(1.5, 18446744073709551615);
326
355
round(1.5, 18446744073709551615) truncate(1.5, 18446744073709551615)
327
0.000000000000000000000000000000 0.000000000000000000000000000000
356
1.500000000000000000000000000000 1.500000000000000000000000000000
328
357
select round(18446744073709551614, -1), truncate(18446744073709551614, -1);
329
358
round(18446744073709551614, -1) truncate(18446744073709551614, -1)
330
359
18446744073709551610 18446744073709551610
331
360
select round(4, -4294967200), truncate(4, -4294967200);
332
361
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);
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));
344
373
INSERT INTO t1 VALUES('1998-09-23', 'str1', 1), ('2003-03-25', 'str2', 0);
345
374
SELECT a DIV 900 y FROM t1 GROUP BY y;