mysql 数学函数
生活随笔
收集整理的這篇文章主要介紹了
mysql 数学函数
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
獲取隨機(jī)數(shù)rand(),rand(x) 四舍五入round(x),round(x,y) y保留小數(shù)點(diǎn)y位,為負(fù)數(shù)時(shí)向左y位 truncate(x,y)直接截取 符號(hào)函數(shù)sign(x) ?x正為1,負(fù)數(shù)為-1 0為0 pow(x,y) x的y次方 exp(x) e的x次方 log(x) e對(duì)x的對(duì)數(shù) log10(x) 10對(duì)x的對(duì)數(shù) radians(x) 角度轉(zhuǎn)弧度 degrees(x) 弧度轉(zhuǎn)角度 sin(x) asin(x) ... char_length(string) 字符串長度 中文一個(gè)字符為3位 length(string)? concat(string1,string2) 連接字符串 insert(s1,x,len,s2)返回字符串s1,s1中起始于x位置長度為len的子字符串將被s2字符串替換 lower(str),lcase(str) 轉(zhuǎn)換為小寫 upper(str),ucase(str) 轉(zhuǎn)換成大寫 獲取left(str,len) 返回從左邊起的len個(gè)字符,right(str,len)返回右邊的類似 lpad(s1,len,s2)返回長度為len的字符串,s1小于len用s2補(bǔ)充 rpad(s1,len,s2)類似于lpad ltrim(s) rtrim(s) trim(s)處理空格 trim(s1 from s) 從s兩端刪除s1,注意只有兩端 repeat(s,n)返回n個(gè)s連接的字符串 space(n) 返回n個(gè)空格的字符串 replace(str,ss1,ss2)吧str中的ss1替換為ss2 strcmp(s1,s2) 相減,結(jié)果為正數(shù)返回1,負(fù)數(shù)返回-1,相等返回0 mid(s,n,len),substring(s,n,len)從s返回長度為len的子串,起始位置n locate(str1,str),position(str1 in str),instr(str,str1) 返回str1在str的位置 reverse(str) 翻轉(zhuǎn)str elt(n,str1,str2,str3.....)返回第n個(gè)字符串或者null field(s,str1,str2,str3)返回第一個(gè)str[i]==s的位置,如在str2==s,返回2 find_in_set(s1,s2)s2是字符串列表以‘,’分開,返回s1在字符串s2的位置 make_set(x,s1,s2...)返回x代表的二進(jìn)制數(shù)對(duì)應(yīng)位置的x[i]*s1+x[i+1]*s2+x[i+2]*s3? x[i]=0或1 curdate(),current_date() 返回當(dāng)前日期 curtime(),current_time()返回時(shí)間 current_timestamp(),localtime(),now(),sysdate() 返回日期時(shí)間 unix_timestamp(date) 1970-1-1到date的秒數(shù),沒有date到當(dāng)前 from_unixtime(date)為unix_timestamp(date)互為反函數(shù) utc_date()返回utc日期 utc_time()返回utc時(shí)間 month(date)返回1-12 monthname(date) 返回january-december dayname(d) sunday-saturday dayofweek(d)返回d對(duì)應(yīng)一周的索引 1-周日 2-周一。。。。 weekday(d) 0-周一,1-周二。。。 week(d)計(jì)算日期d是一年中的第幾周 weekofyear(d) 計(jì)算某天位與一年中的第幾周1-53 year(date)返回年份 quarter(date)返回季節(jié) hour(time)返回小時(shí) minute(time)返回分鐘 second(time)返回秒 extract(type from date)從date提取日期時(shí)間等內(nèi)容 type可以為year,month,year_month等 time_to_sec(time) h*3600+m*60+s sec_to_time(seconds)和time_to_sec互為反函數(shù)
date_add(date,interval expr type),adddate(date,interval expr type) example:DATE_ADD('2010-12-31 23:59:59', INTERVAL 1 SECOND) 返回 2011-1-1 0:0:0 DATE_ADD('2010-12-31 23:59:59', INTERVAL '1:1' MINUTE_SECOND) 2011-1-1 0:1:0 date_sub..... addtime(date,expr) subtime..... date_diff(date1,date2)求差 返回date1-date2 date_format(date,format) format: %w %m %y.... TIME_FORMAT(time,format) GET_FORMAT(date,format_type) if(expr,v1,v2) expr==true 返回v1否則返回v2 ifnull(v1,v2)如果v1不為空返回v1否則返回v2 case expr when v1 then r1 [when v2 then r2] [else rn] end version()版本號(hào) connection_id()當(dāng)前登錄連接數(shù) DATABASE(),SCHEMA();數(shù)據(jù)庫名 USER(), CURRENT_USER(), SYSTEM_USER();用戶 charset(str) str字符串字符集 collation()字符排列順序 last_insert_id();最后一條記錄的ID字段的值(這個(gè)值是insert的第一個(gè)插入值的ID,insert可以一次插入多條記錄), password(str)加密密碼返回加密后的字符串 md5(str) 求出str的MD5(128位) encode(str,pswd_str);用pswd_str對(duì)str進(jìn)行加密 decode(str,pswd_str)與encode相反 format(x,n)將數(shù)字x格式化 conv(N,from_base,to_base)轉(zhuǎn)換進(jìn)制 inet_aton(expr) IP -> int inet_ntoa(expr) int->IP get_lock(str,timeout) 對(duì)名為str的鎖加鎖 release_lock(str)解鎖 is_free_lock(str)判斷 is_used_lock(str)判斷有沒有這個(gè)鎖 benchmark(n,expr) 進(jìn)行n次expr convert(str Using type) 在不同字符集轉(zhuǎn)換用type轉(zhuǎn)換str cast(x, AS type)數(shù)據(jù)類型轉(zhuǎn)換 type: BINARY ,CHAR(N) ,DATE,TIME,DATETIME,DECIMAL,SIGNED,UNSIGNED
date_add(date,interval expr type),adddate(date,interval expr type) example:DATE_ADD('2010-12-31 23:59:59', INTERVAL 1 SECOND) 返回 2011-1-1 0:0:0 DATE_ADD('2010-12-31 23:59:59', INTERVAL '1:1' MINUTE_SECOND) 2011-1-1 0:1:0 date_sub..... addtime(date,expr) subtime..... date_diff(date1,date2)求差 返回date1-date2 date_format(date,format) format: %w %m %y.... TIME_FORMAT(time,format) GET_FORMAT(date,format_type) if(expr,v1,v2) expr==true 返回v1否則返回v2 ifnull(v1,v2)如果v1不為空返回v1否則返回v2 case expr when v1 then r1 [when v2 then r2] [else rn] end version()版本號(hào) connection_id()當(dāng)前登錄連接數(shù) DATABASE(),SCHEMA();數(shù)據(jù)庫名 USER(), CURRENT_USER(), SYSTEM_USER();用戶 charset(str) str字符串字符集 collation()字符排列順序 last_insert_id();最后一條記錄的ID字段的值(這個(gè)值是insert的第一個(gè)插入值的ID,insert可以一次插入多條記錄), password(str)加密密碼返回加密后的字符串 md5(str) 求出str的MD5(128位) encode(str,pswd_str);用pswd_str對(duì)str進(jìn)行加密 decode(str,pswd_str)與encode相反 format(x,n)將數(shù)字x格式化 conv(N,from_base,to_base)轉(zhuǎn)換進(jìn)制 inet_aton(expr) IP -> int inet_ntoa(expr) int->IP get_lock(str,timeout) 對(duì)名為str的鎖加鎖 release_lock(str)解鎖 is_free_lock(str)判斷 is_used_lock(str)判斷有沒有這個(gè)鎖 benchmark(n,expr) 進(jìn)行n次expr convert(str Using type) 在不同字符集轉(zhuǎn)換用type轉(zhuǎn)換str cast(x, AS type)數(shù)據(jù)類型轉(zhuǎn)換 type: BINARY ,CHAR(N) ,DATE,TIME,DATETIME,DECIMAL,SIGNED,UNSIGNED
轉(zhuǎn)載于:https://www.cnblogs.com/cplover/p/3372173.html
總結(jié)
以上是生活随笔為你收集整理的mysql 数学函数的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 12864密码锁
- 下一篇: ELK 构建 MySQL 慢日志收集平台