You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

240 lines
9.5 KiB

22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
  1. drop table if exists t1;
  2. select floor(5.5),floor(-5.5);
  3. floor(5.5) floor(-5.5)
  4. 5 -6
  5. explain extended select floor(5.5),floor(-5.5);
  6. id select_type table type possible_keys key key_len ref rows Extra
  7. 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL No tables used
  8. Warnings:
  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)
  12. 6 -5
  13. explain extended select ceiling(5.5),ceiling(-5.5);
  14. id select_type table type possible_keys key key_len ref rows Extra
  15. 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL No tables used
  16. Warnings:
  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 Extra
  23. 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL No tables used
  24. Warnings:
  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)
  28. 6 -6
  29. explain extended select round(5.5),round(-5.5);
  30. id select_type table type possible_keys key key_len ref rows Extra
  31. 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL No tables used
  32. Warnings:
  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)
  36. 5.6 5.64 10 0
  37. select abs(-10), sign(-5), sign(5), sign(0);
  38. abs(-10) sign(-5) sign(5) sign(0)
  39. 10 -1 1 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 Extra
  42. 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL No tables used
  43. Warnings:
  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 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 Extra
  50. 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL No tables used
  51. Warnings:
  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 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 Extra
  58. 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL No tables used
  59. Warnings:
  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.9068905956085 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 Extra
  66. 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL No tables used
  67. Warnings:
  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.2552725051033 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 Extra
  74. 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL No tables used
  75. Warnings:
  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)
  79. 10 16
  80. explain extended select pow(10,log10(10)),power(2,4);
  81. id select_type table type possible_keys key key_len ref rows Extra
  82. 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL No tables used
  83. Warnings:
  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();
  87. rand(999999) rand()
  88. 0.014231365187309 0.028870999839968
  89. explain extended select rand(999999),rand();
  90. id select_type table type possible_keys key key_len ref rows Extra
  91. 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL No tables used
  92. Warnings:
  93. Note 1003 select sql_no_cache 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 Extra
  99. 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL No tables used
  100. Warnings:
  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.2831853071796
  105. SELECT ACOS(1.0);
  106. ACOS(1.0)
  107. 0
  108. SELECT ASIN(1.0);
  109. ASIN(1.0)
  110. 1.5707963267949
  111. SELECT ACOS(0.2*5.0);
  112. ACOS(0.2*5.0)
  113. 0
  114. SELECT ACOS(0.5*2.0);
  115. ACOS(0.5*2.0)
  116. 0
  117. SELECT ASIN(0.8+0.2);
  118. ASIN(0.8+0.2)
  119. 1.5707963267949
  120. SELECT ASIN(1.2-0.2);
  121. ASIN(1.2-0.2)
  122. 1.5707963267949
  123. select format(4.55, 1), format(4.551, 1);
  124. format(4.55, 1) format(4.551, 1)
  125. 4.6 4.6
  126. explain extended select degrees(pi()),radians(360);
  127. id select_type table type possible_keys key key_len ref rows Extra
  128. 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL No tables used
  129. Warnings:
  130. Note 1003 select degrees(pi()) AS `degrees(pi())`,radians(360) AS `radians(360)`
  131. select rand(rand);
  132. ERROR 42S22: Unknown column 'rand' in 'field list'
  133. create table t1 (col1 int, col2 decimal(60,30));
  134. insert into t1 values(1,1234567890.12345);
  135. select format(col2,7) from t1;
  136. format(col2,7)
  137. 1,234,567,890.1234500
  138. select format(col2,8) from t1;
  139. format(col2,8)
  140. 1,234,567,890.12345000
  141. insert into t1 values(7,1234567890123456.12345);
  142. select format(col2,6) from t1 where col1=7;
  143. format(col2,6)
  144. 1,234,567,890,123,456.123450
  145. drop table t1;
  146. select round(150, 2);
  147. round(150, 2)
  148. 150.00
  149. select ceil(0.09);
  150. ceil(0.09)
  151. 1
  152. select ceil(0.000000000000000009);
  153. ceil(0.000000000000000009)
  154. 1
  155. create table t1 select round(1, 6);
  156. show create table t1;
  157. Table Create Table
  158. t1 CREATE TABLE `t1` (
  159. `round(1, 6)` decimal(7,6) NOT NULL DEFAULT '0.000000'
  160. ) ENGINE=MyISAM DEFAULT CHARSET=latin1
  161. select * from t1;
  162. round(1, 6)
  163. 1.000000
  164. drop table t1;
  165. select abs(-2) * -2;
  166. abs(-2) * -2
  167. -4
  168. create table t1 (i int);
  169. insert into t1 values (1);
  170. select rand(i) from t1;
  171. ERROR HY000: Incorrect arguments to RAND
  172. drop table t1;
  173. create table t1 (a varchar(90), ts datetime not null, index (a)) engine=innodb default charset=utf8;
  174. insert into t1 values ('http://www.foo.com/', now());
  175. select a from t1 where a='http://www.foo.com/' order by abs(timediff(ts, 0));
  176. a
  177. http://www.foo.com/
  178. drop table t1;
  179. set sql_mode='traditional';
  180. select ln(-1);
  181. ln(-1)
  182. NULL
  183. Warnings:
  184. Error 1365 Division by 0
  185. select log10(-1);
  186. log10(-1)
  187. NULL
  188. Warnings:
  189. Error 1365 Division by 0
  190. select log2(-1);
  191. log2(-1)
  192. NULL
  193. Warnings:
  194. Error 1365 Division by 0
  195. select log(2,-1);
  196. log(2,-1)
  197. NULL
  198. Warnings:
  199. Error 1365 Division by 0
  200. select log(-2,1);
  201. log(-2,1)
  202. NULL
  203. Warnings:
  204. Error 1365 Division by 0
  205. set sql_mode='';
  206. select round(111,-10);
  207. round(111,-10)
  208. 0
  209. select round(-5000111000111000155,-1);
  210. round(-5000111000111000155,-1)
  211. -5000111000111000160
  212. select round(15000111000111000155,-1);
  213. round(15000111000111000155,-1)
  214. 15000111000111000160
  215. select truncate(-5000111000111000155,-1);
  216. truncate(-5000111000111000155,-1)
  217. -5000111000111000150
  218. select truncate(15000111000111000155,-1);
  219. truncate(15000111000111000155,-1)
  220. 15000111000111000150
  221. set names utf8;
  222. create table t1
  223. (f1 varchar(32) not null,
  224. f2 smallint(5) unsigned not null,
  225. f3 int(10) unsigned not null default '0')
  226. engine=myisam default charset=utf8;
  227. insert into t1 values ('zombie',0,0),('gold',1,10000),('silver',2,10000);
  228. create table t2
  229. (f1 int(10) unsigned not null,
  230. f2 int(10) unsigned not null,
  231. f3 smallint(5) unsigned not null)
  232. engine=myisam default charset=utf8;
  233. insert into t2 values (16777216,16787215,1),(33554432,33564431,2);
  234. select format(t2.f2-t2.f1+1,0) from t1,t2
  235. where t1.f2 = t2.f3 order by t1.f1;
  236. format(t2.f2-t2.f1+1,0)
  237. 10,000
  238. 10,000
  239. drop table t1, t2;
  240. set names default;