【问题标题】:Cause of ORA-00934: group function is not allowed hereORA-00934 的原因:此处不允许使用组功能
【发布时间】:2020-03-11 06:52:27
【问题描述】:

当我运行以下查询时,我收到以下错误:

ORA-00934:此处不允许使用群组功能

select customer_name, count(product_name) Total 
from customer c
  join orders o
    on c.customer_id=o.customer_id
  join products p
    on o.product_id=p.product_id
where p.product_category='books'
AND order_date between '1-Aug-19' AND sysdate
AND count(product_name)>3
group by customer_name
;

【问题讨论】:

    标签: sql oracle


    【解决方案1】:

    只需将查询更改为:

    select customer_name
           , count(product_name) Total 
    from customer c 
    join orders o on c.customer_id=o.customer_id 
    join products p on o.product_id=p.product_id 
    where p.product_category='books' 
    AND order_date between '1-Aug-19' AND sysdate 
    group by customer_name 
    having count(product_name)>3;
    

    比较聚合时使用HAVING 而不是WHERE。 这是DEMO

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-20
      相关资源
      最近更新 更多