函数
数值函数
- abs(x) 绝对值
- ceil(x) 大于等于x的最小整数
- floor(x) 小于等于x的最大整数
- mod(x,y) x除以y的余数
- round(x,n) 将x四舍五入到n位小数
- rand() 返回一个随机数
字符函数
- char_length(s) 字符长度
- concat(a,b) 字符连接
- instr(s,s1) 返回字符第一次出现的位置,不区分大小写
- lower(a) / upper(b) 大小写转化
- octet_length(s) 返回字符字节长,utf-8字符占据3个字符
- substring(s,n,m) 截取字符从n开始的m个字母,位置计算从1开始
- trim(s1 from s) 删除开头和结尾的字符,默认是空格
日期函数
- current_date 当前日期
- current_time 当前时间
- current_timestamp 当前时间和日期
- extract(p from date) 从日期中提取信息
- datediff(d1, d2) 计算日期之间的天数
- d1 + interval 日期加上时间间隔
select date ‘2011-11-12’ + interval ‘-1’ month t_goodss
转换函数
- cast
别名
列别名和表别名都使用关键字AS
条件表达式
case
case expression
when value1 then result1
when value2 then result2
else --
end
case
when conditon1 then result1
when conditon2 then result2
else --
end
if
if和java中的三目表达式差不多
select if(1<2, '1<2','1>=2') as result;