数值函数
1. round(x, [d]):对x保留d位小数,同时产生四舍五入
select round(1.26, 1);
OK
1.3
2. format_number(x, d):对x进行格式化,同时支持四舍五入,整数部分每隔d位,用逗号隔开
select format_number(1111111111, 3);
OK
1,111,111,111.000
3. floor(x):获取一个不大于x的整数
select floor(3.55);
OK
3
4. ceil(x):获取一个不小于x的整数
select ceil(3.55);
OK
4
5. rand():产生0~1的随机数
数学函数
1. abs(x):取绝对值
select abs(-1);
OK
1
2. pow(a, b):获取a的b次幂
3.sqrt(x) :平方根
条件判断函数
1. if(expr1,expr2,expr3):如果expr1为true,返回expr2,否则返回expr3
2. case when: 多条件表达式
select
age,
case age
when 24 then '少年'
when 25 then 'xxx'
else '老年'
from
xxx
日期函数
1. current_date : 获取当前日期,yyyy-MM-dd
2. current_timestamp:获取当前时间戳,yyyy-MM-dd HH:mm:ss.SSS
3

本文介绍了SQL中的一些常用函数,包括数值函数如round和format_number,数学函数如abs和pow,条件判断函数如if和casewhen,日期函数如current_date和add_months,以及字符串函数和统计函数等,这些函数在数据处理和分析中起到关键作用。

1024

被折叠的 条评论
为什么被折叠?



