北京常用网站,四川建设人力资源网官网,邢台视频优化排名,必要这个网站怎么样MySQL函数 1、字符串函数2、数值函数3、日期函数4、流程函数 1、字符串函数
函数说明concat(s1, s2, …, sn)字符串拼接#xff0c;将 s1, s2, …, sn 拼接成一个字符串lower(str)将字符串 str 全部转为小写upper(str)将字符串 str 全部转为大写lpad(str, n, pad)左填充… MySQL函数 1、字符串函数2、数值函数3、日期函数4、流程函数 1、字符串函数
函数说明concat(s1, s2, …, sn)字符串拼接将 s1, s2, …, sn 拼接成一个字符串lower(str)将字符串 str 全部转为小写upper(str)将字符串 str 全部转为大写lpad(str, n, pad)左填充用字符串 pad 对 str 的左边进行填充达到 n 个字符串长度rpad(str, n, pad)右填充用字符串 pad 对 str 的右边进行填充达到 n 个字符串长度trim(str)去掉字符串头部和尾部的空格substring(str, start, len)返回从字符串 str 从 start 位置起的 len 个长度的字符串索引从 1 开始
-- concat
select concat(hello, MySQL);-- lower
select lower(Hello);-- upper
select upper(Hello);-- lpad
select lpad(hhh, 5, -);-- rpad
select rpad(hhh, 5, -);-- trim
select trim( Hello MySQL! );-- substring
select substring(Hello MySQL, 1, 5);2、数值函数
函数说明ceil(x)向上取整floor(x)向下取整mod(x, y)返回 x/y 的模rand()返回 0~1 内的随机数round(x, y)求参数 x 的四舍五入的值保留 y 为小数
-- ceil
select ceil(1.1);-- floor
select floor(1.1);-- mod
select mod(7, 4);-- rand
select rand();-- round
select round(1.254, 1);3、日期函数
函数说明curdate()返回当前日期年-月-日curtime()返回当前时间时-分-秒now()返回当前日期和时间YEAR(date)获取指定 date 的年份MONTH(date)获取指定 date 的月份DAY(date)获取指定 date 的日期DATE_ADD(date, INTERVAL expr type)返回一个日期/时间值加上一个时间间隔 expr 后的时间值datediff(date1, date2)返回起始时间 date1 和结束时间 date2 之间的天数
-- curdate
select curdate();-- curtime
select curtime();-- now
select now();-- YEAR
select YEAR(now());-- MONTH
select MONTH(now());-- DAY
select DAY(now());-- DATE_ADD
select DATE_ADD(now(), INTERVAL 10 DAY);-- datediff
select datediff(2021-10-01, 2021-06-01);4、流程函数
函数说明if(value, t, f)如果 value 为 true 则返回 t 否则返回 fifnull(value1, value2)如果 value1 不为空 返回 value1 否则返回value2case when [val1] then [res1] when [val2] then [res2] … else [default] end如果 val1 为 true 返回 res1…否则返回 default 默认值case [expr] when [val1] then [res1] when [val2] then [res2] … else [default] end如果 expr 的值等于 val1返回 res1…否则返回 default 默认值
-- if(value, t, f)
select if(true, True, False);
select if(false, True, False);-- ifnull(value1, value2)
select ifnull(OK, Default);
select ifnull(, Default);
select ifnull(null, Default);-- case when [val1] then [res1] when [val2] then [res2] ... else [default] end
select id, name,(case when math 85 then 优秀 when math 60 then 及格 else 不及格 end) as math,(case when english 85 then 优秀 when english 60 then 及格 else 不及格 end) as english,(case when chinese 85 then 优秀 when chinese 60 then 及格 else 不及格 end) as chinese
from score;-- case [expr] when [val1] then [res1] when [val2] then [res2] ... else [default] end
selectid,name,(case address when 北京 then 一线城市 when 上海 then 一线城市 else 二线城市 end) as address
from tb_emp;