分享sql中的一些常用函数,可以随意取道想要的数据。 http://www.ub2b.cn整理分享 无 源码与演示: 源码出处 数字函数abs() 求绝对值(让我想起了abs防抱死系统)ceiling() 舍入到最大整数,-3.6舍入到-3floor() 舍入到最小整数,-3.6舍入到-4round() 四舍五
分享sql中的一些常用函数,可以随意取道想要的数据。
http://www.ub2b.cn整理分享 源码与演示:源码出处
数字函数abs() 求绝对值(让我想起了abs防抱死系统)ceiling() 舍入到最大整数,-3.6舍入到-3floor() 舍入到最小整数,-3.6舍入到-4round() 四舍五入,round(3.141, 2) 需要传入两个参数,前一个为操作数,后一个为精度 字符串函数len() 计算字符串长度lower() 转换为小写字符upper() 转换为大写字符ltrim() 去左空格rtrim() 去右空格substring(string, start_position, lenth) 字符串截取函数,从start_position处开始截取长度为lenth 日期函数getdate() 取当前日期dateadd(datepart, number, date) 函数用于计算增量后的日期,datepart 是计量单位,date 是需要操作的日期 datepart 可选取:year, quarter, month, dayofyear, day, week, weekday, hour, minute, seconddatediff(datepart, startdate, enddate) 根据datepart求得两个日期之间的差值datepart(datepart, date) 返回日期的指定部分 类型转换cast(expression as type)convert(type, expression) 空值处理函数isnull(expression, value) 判断若 expression 不为空返回 expression,否则返回 valueselect isnull(name, '佚名') from person单值判断类似于 switch case 语句。case expressionwhen value1 then return1when value2 then return2else return3end当 when 后做范围判断时,case后可以没有表达式。 row_number() 函数作用是统计行号。row_number()是开窗函数,不能出现在 where 中,只能出现在 select、order by 中。select * from(select row_number() over(order by salary) as rownum, id, name, from person) as e1where e1.rownum > 3 and e1.rownum < 5