Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
执行SQL时没有一个组函数_Sql_Oracle - Fatal编程技术网

执行SQL时没有一个组函数

执行SQL时没有一个组函数,sql,oracle,Sql,Oracle,我在执行SQL时出现此错误,状态:非单个组函数: [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_purchasei

我在执行SQL时出现此错误,状态:非单个组函数:

[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
我搜索了Stackoverflow,但找不到我的原因:


您应该
根据
某些列进行分组:

....
where m.creator='1001A210000000000IIQ'
group by bd.name,
         substr(m.code,0,4)
order by substr(m.code,0,4);

当p.vbdef4='~'然后是'0'时,您可以找到问题
的解决方案,否则p.vbdef4 end
看起来很奇怪。列p.vbdef4的数据类型?
p.vdbef4
是char,默认值可能是
'~'
。这似乎与可能重复的谢谢没有太大区别,您的答案是正确的,您能告诉我为什么要在group by上添加
substr(m.code,0,4)
?所有选定的列,不涉及分组函数(sum、max等),应包括在分组列表中。
....
where m.creator='1001A210000000000IIQ'
group by bd.name,
         substr(m.code,0,4)
order by substr(m.code,0,4);