【问题标题】:Not a single-group group function when I execute my SQL执行 SQL 时不是单组组函数
【发布时间】:2017-08-24 02:44:16
【问题描述】:

执行 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

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)

我搜索了 Stackoverflow,但找不到我的原因:

SQL not a single-group group function

【问题讨论】:

标签: sql oracle


【解决方案1】:

你应该group by一些栏目:

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

【讨论】:

  • 谢谢你,你的回答是正确的,你能告诉我为什么要在group by上加substr(m.code,0,4)吗?
  • 所有未参与分组函数(sum、max等)的选定列都应包含在分组列表中。
猜你喜欢
  • 2023-03-23
  • 1970-01-01
  • 1970-01-01
  • 2014-06-21
  • 1970-01-01
  • 1970-01-01
  • 2018-04-07
  • 2012-04-16
  • 1970-01-01
相关资源
最近更新 更多