SQL查询,常用的一些函数!

来源:互联网 发布:stm32f10x数据手册 编辑:程序博客网 时间:2024/04/29 17:16

日常工作和学习多,为了方便查询,多半要用到这些函数 ,做个简单罗列 !

用SQL进行函数查询
ceil函数
ceil(n),去大于等于数值n的最小整数
    e:select mgr, mgr/100,ceil(mgr/100) from scott.emp;
floor函数
floor(n),取小于等于数值n的最大整数
     e:select mgr, mgr/100,floor(mgr/100) from scott.emp;
mod函数
mod(m,n)取m整除n后的余数
     e:select  mgr,  mod(mgr,1000),  mod(mgr,100),  mod(mgr,10)  from  scott.emp;
power函数
power(m,n)取m的n次方
    e:select mgr, power(mgr,2),power(mgr,3) from scott.emp;
round函数
round(m,n),四舍五入,保留n位
    e:select mgr, round(mgr/100,2),round(mgr/1000,2) from scott.emp;
sign函数
sign(n),n>0,取1;n=0,取0;n<0,取-1.
    e:select mgr, mgr-7800,sign(mgr-7800) from scott.emp;
avg函数
avg(字段名),求平均值,要求字段必须为数值型
    e:select avg(mgr) 平均薪水 from scott.emp;
count函数
count(字段名)或(*),统计总数
    e:select count(*) 记录总数 from scott.emp;
    select count(distinct job ) 工作类别总数 from scott.emp;
min函数
min(字段名),计算数值型字段最小数
    e:select min(sal) 最少薪水 from scott.emp;
max函数
max(字段名),计算数值型字段的最大值
    e:select max(sal) 最高薪水 from scott.emp;
sum函数
sum(字段名),计算数值型字段的总和
    e:select sum(sal) 薪水总和 from scott.emp;

原创粉丝点击