-2

I get this error when I execute my SQL, state: Not a single-group group function :

[SQL]select distinct bd.name aaa,
       substr(m.code,0,4) as mcode,
       sum(p.nassistnum) BB,
       sum(case when p.vbdef4='~' then '0' else p.vbdef4 end) CC
        from bd_material_v m 
        inner join ic_purchasein_b p
           on m.pk_source=p.cmaterialvid
        inner join ic_purchasein_h h 
           on  h.cgeneralhid = p.cgeneralhid and  h.ctrantypeid='1001A210000000002UW7' and h.vdef8='~'
        inner join bd_marbasclass bd
           on bd.code=substr(m.code,0,4)
        where m.creator='1001A210000000000IIQ' 
      order by substr(m.code,0,4)        
    --  and h.pk_org in (parameter('param3'))
                    --    and substr(h.dbilldate,1,10) >= parameter('param1')
                     --   and substr(h.dbilldate,1,10) <= parameter('param2')
[Err] ORA-00937: not a single-group group function

The SQL is below:

select distinct bd.name aaa,
       substr(m.code,0,4) as mcode,
       sum(p.nassistnum) BB,
       sum(case when p.vbdef4='~' then '0' else p.vbdef4 end) CC
        from bd_material_v m 
        inner join ic_purchasein_b p
           on m.pk_source=p.cmaterialvid
        inner join ic_purchasein_h h 
           on  h.cgeneralhid = p.cgeneralhid and h.ctrantypeid='1001A210000000002UW7' and h.vdef8='~'
        inner join bd_marbasclass bd
           on bd.code=substr(m.code,0,4)
        where m.creator='1001A210000000000IIQ' 
      order by substr(m.code,0,4)

I searched Stackoverflow, but I can not find the reason of mine:

SQL not a single-group group function

Community
  • 1
  • 1
qg_java_17137
  • 3,310
  • 10
  • 41
  • 84

1 Answers1

0

You should group by some columns:

....
where m.creator='1001A210000000000IIQ'
group by bd.name,
         substr(m.code,0,4)
order by substr(m.code,0,4);
Robert Kock
  • 5,795
  • 1
  • 12
  • 20