select distinct h.batchno as 批次号,
                h.gpolicyno as 保单号,
                c.name as 姓名,
                h.pid as 身份证号,
                h.listtype as 单据类型,
                sum(h.sumrec) as 总金额,
                sum(h.payrec) as 自费金额,
                sum(h.pay2rec) as 自付二金额,
                sum(h.plapay) as 统支金额,
                sum(h.pay1rec) as 自付一金额,
                sum(socadd) as 社保补充,
                hg.workst as 类别,
                sum(h.deductiblerec) as 免赔额,
                nvl(h.selfscale, 0) as 自付段比例,
                nvl(h.togscale, 0) as 共付段比例,
                sum(h.socbase) as 社保起付线,
                sum(reducerec) as 交叉扣减金额,
                sum(recmod) as 金额调整,
                sum(h.selfpay) as 自付段给付,
                sum(h.togpay) as 共付段给付,
                sum(h.paymentrec) as 计算给付金额,
                h.printst as 分割单开据,
                dr.cdg_batch as 华道批次号,
                dr.CDG_POINTS_CASE_NO as 华道分案号,
                hc.oc_sqrq as 理赔申请日期
  from hclaimlist_cli h
  left join custmatl c
    on h.pid = c.id
  left join V_HGRPLIST hg
    on h.pid = hg.pid
   and h.gpolicyno = hg.gpolicyno
  left join v_gpolicyno_company g
    on h.gpolicyno = g.gpolicyno
  left join hclaimlist hc
    on h.batchno = hc.batchno
  left join hhosinfo a
    on h.hosid = a.hosid
  left join hillinfo b
    on h.illid = b.illid
  left join security_users d
    on h.operno = d.name
  left join security_users e
    on h.c_fhry = e.name
  left join dr_cdg_date dr
    on h.Claimdocno = dr.claimdocno
 where 
   h.respcode in ('27341100', '27490100')
   and h.listtype='4'
   and h.batchno in ('J1200073')
 group by h.batchno,
          h.gpolicyno,
          c.name,
          h.pid,
          h.listtype,
          hg.workst,
          h.selfscale,
          h.togscale,
          h.printst,
          dr.cdg_batch,
          hc.oc_sqrq,
          dr.CDG_POINTS_CASE_NO    union all
    select distinct h.batchno as 批次号,
                h.gpolicyno as 保单号,
                c.name as 姓名,
                h.pid as 身份证号,
                h.listtype as 单据类型,
                h.sumrec as 总金额,
                h.payrec as 自费金额,
                h.pay2rec as 自付二金额,
                h.plapay as 统支金额,
                h.pay1rec as 自付一金额,
                socadd as 社保补充,
                hg.workst as 类别,
                h.deductiblerec as 免赔额,
                nvl(h.selfscale, 0) as 自付段比例,
                nvl(h.togscale, 0) as 共付段比例,
                h.socbase as 社保起付线,
                reducerec as 交叉扣减金额,
                recmod as 金额调整,
                nvl(h.selfpay,0) as 自付段给付,
                nvl(h.togpay,0) as 共付段给付,
                h.paymentrec as 计算给付金额,
                h.printst as 分割单开据,
                dr.cdg_batch as 华道批次号,
                dr.CDG_POINTS_CASE_NO as 华道分案号,
                hc.oc_sqrq as 理赔申请日期
  from hclaimlist_cli h
  left join custmatl c
    on h.pid = c.id
  left join V_HGRPLIST hg
    on h.pid = hg.pid
   and h.gpolicyno = hg.gpolicyno
  left join v_gpolicyno_company g
    on h.gpolicyno = g.gpolicyno
  left join hclaimlist hc
    on h.batchno = hc.batchno
  left join hhosinfo a
    on h.hosid = a.hosid
  left join hillinfo b
    on h.illid = b.illid
  left join security_users d
    on h.operno = d.name
  left join security_users e
    on h.c_fhry = e.name
  left join dr_cdg_date dr
    on h.Claimdocno = dr.claimdocno
 where 
   h.respcode in ('27341100', '27490100')
   and h.listtype not in('4')
   and h.batchno in ('J1200073')

解决方案 »

  1.   

    1.建议俩段sql分开执行以下,看看报错是那一段;
    2.是不是俩段sql字段类型、字段数不等;
    3.第一段的sql中 distinct 没有必要。
      

  2.   

    把建表的sql脚本传一下,要不怎么测试,这一行一行看,没信心啊。
      

  3.   

    你UNION ALL下面那个语句也要group by 下吧!
      

  4.   

    不行啊,我加了也不行啊,我下面那条语句没有用sum(),不加也可以吧。