PLSQL 分组分析日期函数(去空三剑客)

--去空三剑客

4.coalesce(参1,参2....)      多个参数中第一个不为空的值

select coalesce(null,null,123,null,456)
from dual

--查询提成,经理编号,工资
--以及他们中第一个不为空的值
select comm,mgr,sal,coalesce(comm,mgr,sal)
from emp


去空:coalesce(comm,0)
     
--查询每位员工每个月的总工资
select sal,comm,sal+coalesce(comm,0)
from emp

5.nvl(参1,参2)       参数1位空返回参数2,否则返回参数1

select nvl(null,0)
from dual


--查询每个人的姓名和他们的月薪
select ename,sal+nvl(comm,0)
from emp


6.nvl2(参1,参2,参3)     参1为空返回参数3,否则返回参数2

select nvl2(null,2,3),nvl2(1,2,3)
from dual


--如果经理编号为空则返回大哥,否则返回小弟
select ename,nvl2(mgr,'小弟','大哥')
from emp


7.distinct    去重
书写位置紧跟着select

select distinct deptno,job
from emp

--查询emp表有几个部门
select distinct deptno 
from emp


--查询emp表有几个职位
select distinct job
from emp


--查询emp表有几种部门职位
select distinct deptno,job
from emp


8.case when
(1) case 列 when 列中值1  then 值1
            when 列中值2  then 值2
            ...
            [else  值n]
    end

select deptno,
       case deptno when 10 then '十部门'
                   when 20 then '二十部门'
                   else '三十部门'
       end A
from emp

--查询员工表的职位,和中文职位
select job,case job when 'CLERK' then '职员'
                    when 'SALESMAN' then '销售员'
                    when 'MANAGER' then '经理'
                    when 'PRESIDENT' then '董事长'
                    when 'ANALYST' then '分析员'
           end 中文职位
from emp


--查询员工表的部门,和中文部门
select dname,case dname when 'ACCOUNTING'  then '财务部'
                        when 'RESEARCH'    then '研发部'
                        when 'SALES'       then '销售部'
                        when 'OPERATIONS'  then '营运部'
             end 中文部门
from dept<

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值