nvl与case when

1、不用CASE,用NVL函数即可:
SELECT sid,NVL(sname,'姓名为空' ) from stuinfo;

2、CASE:
SELECT sid,
CASE WHEN snameIS NULL THEN '姓名为空' ELSE sname END CASE
from stuinfo;
select year,sum(nvl(case when jclx='1' then jccs end,0)) as rcjcjccs,sum(nvl(case when jclx='1' then jccs end,0))-sum(nvl(case when jclx='1' then hgs end,0)) as rcjcbhgs ,sum(nvl(case when jclx='2' then jccs end,0)) as zxjcjccs,sum(nvl(case when jclx='2' then jccs end,0))-sum(nvl(case when jclx='2' then hgs end,0)) as zxjcbhgs ,sum(nvl(case when jclx='3' then jccs end,0)) as fxjcjccs,sum(nvl(case when jclx='3' then jccs end,0))-sum(nvl(case when jclx='3' then hgs end,0)) as fxjcbhgs ,sum(nvl(case when jclx='4' then jccs end,0)) as xkjcjccs,sum(nvl(case when jclx='4' then jccs end,0))-sum(nvl(case when jclx='4' then hgs end,0)) as xkjcbhgs ,sum(nvl(case when jclx='5' then jccs end,0)) as zgfccs,sum(nvl(case when jclx='5' then jccs end,0))-sum(nvl(case when jclx='5' then hgs end,0)) as zgfcbhgs ,sum(nvl(case when jclx='7' then jccs end,0)) as txjcjccs,sum(nvl(case when jclx='7' then jccs end,0))-sum(nvl(case when jclx='7' then hgs end,0)) as txjcbhgs ,sum(nvl(case when jclx='9' then jccs end,0)) as sjjcjccs,sum(nvl(case when jclx='9' then jccs end,0))-sum(nvl(case when jclx='9' then hgs end,0)) as sjjcbhgs ,sum(nvl(case when jclx='10' then jccs end,0)) as yyjcjccs,sum(nvl(case when jclx='10' then jccs end,0))-sum(nvl(case when jclx='10' then hgs end,0)) as yyjcbhgs ,sum(nvl(case when jclx='11' then jccs end,0)) as zchcjccs,sum(nvl(case when jclx='11' then jccs end,0))-sum(nvl(case when jclx='11' then hgs end,0)) as zchcbhgs ,sum(nvl(case when jclx='12' then jccs end,0)) as bahcjccs,sum(nvl(case when jclx='12' then jccs end,0))-sum(nvl(case when jclx='12' then hgs end,0)) as bahcbhgs from ( select case when jcbz='1' then '5' else jclx end as jclx, year,jccs,hgs from ( select rec.jclx,rec.jcbz, rec.year, COUNT( rec.ID ) AS jccs, SUM( CASE aa10.AAA103 WHEN '不符合' THEN '0' ELSE '1' END) as hgs from t_inspect_record rec join AMR_ENTERPRISE.t_pub_enterprise ent on rec.ztlsh = ent.id JOIN aa10a1 aa10 ON ( rec.JCJG = aa10.AAA102 AND aa10.AAA100 = 'JCJG' ) WHERE rec.ZT = 1 AND rec.STATUS = 1 and (rec.sszy='10' or rec.sszy='11') group by rec.jclx,rec.jcbz,rec.year order by rec.jclx,rec.jcbz,rec.year) ) where 1=1 and year=':year' group by year order by year 以上是一个sql,我想通过正则表达式,以from、join为关键字,分析出查询sql中涉及的表名
最新发布
06-01
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值