作业帮 > 综合 > 作业

SQL语句case when

来源:学生作业帮 编辑:灵鹊做题网作业帮 分类:综合作业 时间:2024/04/28 02:53:43
SQL语句case when
select    trunc(date '2009-01-01','dd') as date_id,          b.org_id as org_id,          b.risk_id as risk_id,          sum(a.planfee-nvl(c.payreffee,0)) ,          (case when to_char(statistic_date-payrefdate>=0) and to_char(statistic_date-payrefdate<90) then sum(a.planfee-nvl(c.payreffee,0))  else '' end),          (case when to_char(statistic_date-payrefdate>=90) and to_char(statistic_date-payrefdate<180) then sum(a.planfee-nvl(c.payreffee,0))  else '' end),          (case when to_char(statistic_date-payrefdate>=180) and to_char(statistic_date-payrefdate<360) then sum(a.planfee-nvl(c.payreffee,0))  else '' end),          (case when to_char(statistic_date-payrefdate>=360) and to_char(statistic_date-payrefdate<720) then sum(a.planfee-nvl(c.payreffee,0))  else '' end),          (case when to_char(statistic_date-payrefdate>=720) then sum(a.planfee-nvl(c.payreffee,0)) else '' end)          from dm_f_prpjplanfee_prop a,dm_policy_prop_cnt b,(select certino,serialno,sum(payreffee) as payreffee from dm_f_prpjpayrefrec_prop where payrefdate<=(date'2009-01-31') group by certino,serialno)  cwhere   a.certino=b.endorse_no  and a.certino=c.certino(+) and a.serialno=c.serialno(+)and     not exists (select 1                   from dm_policy_prop_cnt                  where b.policy_no = policy_no                    and endorse_type_code = '19'                    and certi_type = 'E'                    and statistic_date <= date  '2009-01-31')                    --and b.policy_no='605012008110000000741'                    and b.statistic_date <= date  '2009-01-31' group by trunc(date '2009-01-31','dd'),b.org_id,b.risk_id  这是一个SQL里面的case when语句,如果执行这个语句,会提示缺少右括号,但如果把case when语句去掉,就可以执行这个语句.
SQL语句case when
太长了,但是看到一个问题,case when,要求返回的类型必须一直.
你看你的第一个case when语句
(case when to_char(statistic_date-payrefdate>=0) and to_char(statistic_date-payrefdate