2005-04-19 11:44:54 +02:00
drop table if exists t1;
2001-09-28 07:05:54 +02:00
select floor(5.5),floor(-5.5);
2000-12-28 02:56:38 +01:00
floor(5.5) floor(-5.5)
5 -6
2003-10-31 10:52:01 +01:00
explain extended select floor(5.5),floor(-5.5);
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings:
2004-05-13 22:47:20 +02:00
Note 1003 select floor(5.5) AS `floor(5.5)`,floor(-(5.5)) AS `floor(-5.5)`
2001-09-28 07:05:54 +02:00
select ceiling(5.5),ceiling(-5.5);
2000-12-28 02:56:38 +01:00
ceiling(5.5) ceiling(-5.5)
6 -5
2003-10-31 10:52:01 +01:00
explain extended select ceiling(5.5),ceiling(-5.5);
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings:
2004-05-13 22:47:20 +02:00
Note 1003 select ceiling(5.5) AS `ceiling(5.5)`,ceiling(-(5.5)) AS `ceiling(-5.5)`
2002-06-03 23:40:27 +02:00
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);
2002-05-31 14:22:38 +02:00
truncate(52.64,1) truncate(52.64,2) truncate(52.64,-1) truncate(52.64,-2) truncate(-52.64,1) truncate(-52.64,-1)
52.6 52.64 50 0 -52.6 -50
2003-10-31 10:52:01 +01:00
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);
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings:
2004-05-13 22:47:20 +02:00
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)`
2002-06-03 23:40:27 +02:00
select round(5.5),round(-5.5);
2000-12-28 02:56:38 +01:00
round(5.5) round(-5.5)
6 -6
2003-10-31 10:52:01 +01:00
explain extended select round(5.5),round(-5.5);
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings:
2004-05-13 22:47:20 +02:00
Note 1003 select round(5.5,0) AS `round(5.5)`,round(-(5.5),0) AS `round(-5.5)`
2001-09-28 07:05:54 +02:00
select round(5.64,1),round(5.64,2),round(5.64,-1),round(5.64,-2);
2000-12-28 02:56:38 +01:00
round(5.64,1) round(5.64,2) round(5.64,-1) round(5.64,-2)
5.6 5.64 10 0
2001-09-28 07:05:54 +02:00
select abs(-10), sign(-5), sign(5), sign(0);
2000-12-28 02:56:38 +01:00
abs(-10) sign(-5) sign(5) sign(0)
10 -1 1 0
2003-10-30 11:57:26 +01:00
explain extended select abs(-10), sign(-5), sign(5), sign(0);
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings:
2004-05-13 22:47:20 +02:00
Note 1003 select abs(-(10)) AS `abs(-10)`,sign(-(5)) AS `sign(-5)`,sign(5) AS `sign(5)`,sign(0) AS `sign(0)`
2002-07-17 10:11:48 +02:00
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);
log(exp(10)) exp(log(sqrt(10))*2) log(-1) log(NULL) log(1,1) log(3,9) log(-1,2) log(NULL,2)
2004-08-19 03:02:09 +02:00
10 10 NULL NULL NULL 2 NULL NULL
2003-10-31 10:52:01 +01:00
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);
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings:
2004-05-13 22:47:20 +02:00
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)`
2002-07-17 10:11:48 +02:00
select ln(exp(10)),exp(ln(sqrt(10))*2),ln(-1),ln(0),ln(NULL);
ln(exp(10)) exp(ln(sqrt(10))*2) ln(-1) ln(0) ln(NULL)
2004-08-19 03:02:09 +02:00
10 10 NULL NULL NULL
2003-10-31 10:52:01 +01:00
explain extended select ln(exp(10)),exp(ln(sqrt(10))*2),ln(-1),ln(0),ln(NULL);
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings:
2004-05-13 22:47:20 +02:00
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)`
2002-07-17 10:11:48 +02:00
select log2(8),log2(15),log2(-2),log2(0),log2(NULL);
log2(8) log2(15) log2(-2) log2(0) log2(NULL)
2004-08-19 03:02:09 +02:00
3 3.9068905956085 NULL NULL NULL
2003-10-31 10:52:01 +01:00
explain extended select log2(8),log2(15),log2(-2),log2(0),log2(NULL);
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings:
2004-05-13 22:47:20 +02:00
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)`
2002-07-17 10:11:48 +02:00
select log10(100),log10(18),log10(-4),log10(0),log10(NULL);
log10(100) log10(18) log10(-4) log10(0) log10(NULL)
2004-08-19 03:02:09 +02:00
2 1.2552725051033 NULL NULL NULL
2003-10-31 10:52:01 +01:00
explain extended select log10(100),log10(18),log10(-4),log10(0),log10(NULL);
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings:
2004-05-13 22:47:20 +02:00
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)`
2001-09-28 07:05:54 +02:00
select pow(10,log10(10)),power(2,4);
2000-12-28 02:56:38 +01:00
pow(10,log10(10)) power(2,4)
2004-08-19 03:02:09 +02:00
10 16
2003-10-31 10:52:01 +01:00
explain extended select pow(10,log10(10)),power(2,4);
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings:
2004-05-13 22:47:20 +02:00
Note 1003 select pow(10,log10(10)) AS `pow(10,log10(10))`,pow(2,4) AS `power(2,4)`
2002-12-03 12:08:25 +01:00
set @@rand_seed1=10000000,@@rand_seed2=1000000;
2001-09-28 07:05:54 +02:00
select rand(999999),rand();
2000-12-28 02:56:38 +01:00
rand(999999) rand()
2002-12-03 12:08:25 +01:00
0.014231365187309 0.028870999839968
2003-10-31 10:52:01 +01:00
explain extended select rand(999999),rand();
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings:
2004-05-13 22:47:20 +02:00
Note 1003 select sql_no_cache rand(999999) AS `rand(999999)`,rand() AS `rand()`
2004-08-19 03:02:09 +02:00
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);
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)
3.141593 1.000000 0.000000 0.000000 0.642093 1.570796 1.570796 0.785398
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);
2003-10-31 10:52:01 +01:00
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings:
2004-08-19 03:02:09 +02:00
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)`
2001-09-28 07:05:54 +02:00
select degrees(pi()),radians(360);
2000-12-28 02:56:38 +01:00
degrees(pi()) radians(360)
180 6.2831853071796
2004-02-06 14:40:44 +01:00
SELECT ACOS(1.0);
2004-01-13 03:47:26 +01:00
ACOS(1.0)
2004-08-19 03:02:09 +02:00
0
2004-02-06 14:40:44 +01:00
SELECT ASIN(1.0);
2004-01-13 03:47:26 +01:00
ASIN(1.0)
2004-08-19 03:02:09 +02:00
1.5707963267949
2004-02-06 14:40:44 +01:00
SELECT ACOS(0.2*5.0);
2004-01-13 03:47:26 +01:00
ACOS(0.2*5.0)
2004-08-19 03:02:09 +02:00
0
2004-02-06 14:40:44 +01:00
SELECT ACOS(0.5*2.0);
2004-01-13 03:47:26 +01:00
ACOS(0.5*2.0)
2004-08-19 03:02:09 +02:00
0
2004-02-06 14:40:44 +01:00
SELECT ASIN(0.8+0.2);
2004-01-13 03:47:26 +01:00
ASIN(0.8+0.2)
2004-08-19 03:02:09 +02:00
1.5707963267949
2004-02-06 14:40:44 +01:00
SELECT ASIN(1.2-0.2);
2004-01-13 03:47:26 +01:00
ASIN(1.2-0.2)
2004-08-19 03:02:09 +02:00
1.5707963267949
2005-05-19 22:04:08 +02:00
select format(4.55, 1), format(4.551, 1);
format(4.55, 1) format(4.551, 1)
4.6 4.6
2003-10-31 10:52:01 +01:00
explain extended select degrees(pi()),radians(360);
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings:
2004-05-13 22:47:20 +02:00
Note 1003 select degrees(pi()) AS `degrees(pi())`,radians(360) AS `radians(360)`
2004-12-20 10:47:38 +01:00
select rand(rand);
ERROR 42S22: Unknown column 'rand' in 'field list'
2005-06-08 12:49:36 +02:00
create table t1 (col1 int, col2 decimal(60,30));
insert into t1 values(1,1234567890.12345);
select format(col2,7) from t1;
format(col2,7)
1,234,567,890.1234500
select format(col2,8) from t1;
format(col2,8)
1,234,567,890.12345000
insert into t1 values(7,1234567890123456.12345);
select format(col2,6) from t1 where col1=7;
format(col2,6)
1,234,567,890,123,456.123450
drop table t1;
2005-06-09 12:27:26 +02:00
select round(150, 2);
round(150, 2)
150.00
2005-06-15 16:53:40 +02:00
select ceil(0.09);
ceil(0.09)
1
select ceil(0.000000000000000009);
ceil(0.000000000000000009)
1
2005-08-02 04:21:56 +02:00
create table t1 select round(1, 6);
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`round(1, 6)` decimal(7,6) NOT NULL default '0.000000'
) ENGINE=MyISAM DEFAULT CHARSET=latin1
select * from t1;
round(1, 6)
1.000000
drop table t1;
2005-06-23 05:00:21 +02:00
select abs(-2) * -2;
abs(-2) * -2
-4
2005-09-06 13:19:59 +02:00
create table t1 (i int);
insert into t1 values (1);
select rand(i) from t1;
ERROR HY000: Incorrect arguments to RAND
drop table t1;
2005-10-18 02:00:42 +02:00
create table t1 (a varchar(90), ts datetime not null, index (a)) engine=innodb default charset=utf8;
insert into t1 values ('http://www.foo.com/', now());
select a from t1 where a='http://www.foo.com/' order by abs(timediff(ts, 0));
a
http://www.foo.com/
drop table t1;
2005-10-17 09:32:22 +02:00
set sql_mode='traditional';
select ln(-1);
ln(-1)
NULL
Warnings:
Error 1365 Division by 0
select log10(-1);
log10(-1)
NULL
Warnings:
Error 1365 Division by 0
select log2(-1);
log2(-1)
NULL
Warnings:
Error 1365 Division by 0
select log(2,-1);
log(2,-1)
NULL
Warnings:
Error 1365 Division by 0
select log(-2,1);
log(-2,1)
NULL
Warnings:
Error 1365 Division by 0
set sql_mode='';
2006-02-07 13:26:35 +01:00
select round(111,-10);
round(111,-10)
0
select round(-5000111000111000155,-1);
round(-5000111000111000155,-1)
-5000111000111000160
select round(15000111000111000155,-1);
round(15000111000111000155,-1)
15000111000111000160
select truncate(-5000111000111000155,-1);
truncate(-5000111000111000155,-1)
-5000111000111000150
select truncate(15000111000111000155,-1);
truncate(15000111000111000155,-1)
15000111000111000150
2006-03-06 09:52:38 +01:00
set names utf8;
create table t1
(f1 varchar(32) not null,
f2 smallint(5) unsigned not null,
f3 int(10) unsigned not null default '0')
engine=myisam default charset=utf8;
insert into t1 values ('zombie',0,0),('gold',1,10000),('silver',2,10000);
create table t2
(f1 int(10) unsigned not null,
f2 int(10) unsigned not null,
f3 smallint(5) unsigned not null)
engine=myisam default charset=utf8;
insert into t2 values (16777216,16787215,1),(33554432,33564431,2);
select format(t2.f2-t2.f1+1,0) from t1,t2
where t1.f2 = t2.f3 order by t1.f1;
format(t2.f2-t2.f1+1,0)
10,000
10,000
drop table t1, t2;
set names default;