MySql常用函式(流程函式和其他)

2021-05-27 07:10:21 字數 934 閱讀 6928

流程函式(函式、功能)

1、if(value,t f):如果value是真,返回t,否則返回f

eg:select userid, if(salary>2000,'high','low') from salary;

2、ifnull(value1,value2):如果value1不為空返回value1,否則返回value2

eg:select userid, ifnull(salary,0) from salary;

3、case when[value1] then[result1]...else [default] end:如果value1是真,返回result,否則返回default

eg:select  userid,case when salary<=2000 then 'low' else 'high' end from salary;

4、case [expr] when [value1] then[result1]... else [defult] end:如果expr等於value1,返回result1,否則返回default

eg:select userid,case salary when 1000 then 'low' when 2000 then 'mid' else 'high' end as sal from salary;

其他函式(函式、功能)

1、database():返回當前資料庫名

2、version():返回當前資料庫版本

3、user():返回當前登入使用者名稱

4、inet_aton(ip):返回ip位址的數字表示

5、inet_ntoa(num):返回數字代表的ip位址

6、password(str):返回字串str的加密版本

7、md5():返回字串str的md5值

eg:select database(),version(),user();

MYSQL常用函式(時間和日期函式)

curdate 或current date 返回當前的日期 curtime 或current time 返回當前的時間 date add date,interval int keyword 返回日期date加上間隔時間int的結果 int必須按照關鍵字進行格式化 如 selectdate add c...

mysql 常用函式迴圈 mysql 常用函式

mysql 常用函式 數字函式 ceiling x 返回大於x的最小整數值 floor x 返回小於x的最大整數值 truncate x,y 返回數字x截短為y位小數的結果 僅僅只是截斷,不會進行四捨五入計算 聚合函式 group concat col 返回由屬於一組的列值連線組合而成的結果 字串函...

mysql常用函式哪些 MySQL常用函式彙總

數學類函式 ceil x ceilin x 進一取整 floor x 捨掉小數部分 round x,y 四捨五入 保留y位小數 mod x,y x除以y以後的餘數 abs x 取x的絕對值 power x,y pow x,y 冪運算 x的y次冪 pi 圓周率 rand 或者rand x 0 1之間的...