標籤:ted unix時間 rom curd 返回 max 空格 table 10個
字串函數
select concat(‘hello‘,‘word‘,‘my‘) myname; // concat() 連結字元函數 輸出 hellowordmy myname是別名select lcase(‘MYSQL‘); //lcase() 轉化成小寫 輸出 mysql select length(‘string‘) //length() 輸出字串的長度select ltrim(‘ strimg‘); //ltrim() 去除左邊空格select rtrim(‘string ‘); //rtrim() 去除右邊空格select repeat(‘php,‘,3); //repeat() 重複次數 輸出 php,php,php,select replace(‘linux is very good‘,‘linux‘,‘php‘) ; //replace()替換 輸出 php is very goodselect substr(‘linux is very good‘,1,5); //substr(),mysql 的起始位置是1,輸出linuxselect space(10); //space(); 產生10個空格
數學函數
select bin(192); //bin(); 十進位轉二進位 ,輸出 11000000select celing(10.1); //celing(); 向上取整 輸出 11select floor(10.1); //floor(); 向下取整 輸出 10select max(col); // max() 取最大值 彙總使用select min(col) //min() 取最小值 彙總使用select sqrt(4); //sqrt() 開平方,輸出2select rand(); // rand() 隨機 select * from tablename order by rand()
日期函數
select curdate(); //curdate(); 當前日期 年月日select curtime(); //curtime(); 目前時間 時分秒select now(); //now(); 現在的日期和時間 年月日時分秒select unix_timestamp(); //unix_timestamp(); 返回當前unix時間戳記select week(‘2015-10-10‘); //week(); 返回當年的第幾周select year(‘2016-06-26‘); //year(); 輸出 2016 ,返回當前的年份select datediff(‘2016-10-10‘,‘2016-10-20‘); // 輸出-10,返回兩個日期相差幾天
Mysql內建函數