不是 GROUP BY 表达式

发布于 2024-12-26 06:37:19 字数 1425 浏览 2 评论 0原文

我有以下选择:

Select attribut1, dateattribut, attribut3, 
       attribut4, attribut15, town_CODE, count(*)     
from (
select attribut1, dateattribut, attribut3, attribut4, attribut15, (CASE 
  WHEN  TO_CHAR(dateattribut,'YYYY')  = '2005'  THEN 
   CASE town_CODE 
    WHEN '039' THEN  '078' WHEN '050' THEN  '093' 
    WHEN '091' THEN  '008' WHEN '102' THEN  '093' 
   ELSE town_CODE end 
  ELSE town_CODE end) as town_CODE
from towntable) GROUP BY attribut1, dateattribut, 
                        attribut3, attribut4, 
                        attribut15, town_CODE
having count(*) > 1;

当我在我们的服务器上执行此查询时,它工作正常。但在我客户的服务器上,我收到oracle错误ORA-00979:不是GROUP BY表达式

到目前为止,我发现我的案例和别名有问题。 没有这个它就可以工作。

有什么建议吗?

*我试图用这个语句做的是获取所有复式条目。通过内部查询,我将所有旧代码更改为新代码,然后我想将它们分组以查看它们是否存在多次。 有些客户确实使用了旧代码,现在他们可能两次使用同一个城镇。

编辑

SELECT * FROM Product_Component_version

,我得到了两个:

Product                                     Version         Status

NLSRTL                                      10.2.0.4.0      Production
Oracle Database 10g Enterprise Edition      10.2.0.4.0      64bi
PL/SQL                                      10.2.0.4.0      Production
TNS for 64-bit Windows:                     10.2.0.4.0      Production

edit2

我的测试表明他不喜欢使用别名调用。 是否有一个设置无法识别别名?

i've following select:

Select attribut1, dateattribut, attribut3, 
       attribut4, attribut15, town_CODE, count(*)     
from (
select attribut1, dateattribut, attribut3, attribut4, attribut15, (CASE 
  WHEN  TO_CHAR(dateattribut,'YYYY')  = '2005'  THEN 
   CASE town_CODE 
    WHEN '039' THEN  '078' WHEN '050' THEN  '093' 
    WHEN '091' THEN  '008' WHEN '102' THEN  '093' 
   ELSE town_CODE end 
  ELSE town_CODE end) as town_CODE
from towntable) GROUP BY attribut1, dateattribut, 
                        attribut3, attribut4, 
                        attribut15, town_CODE
having count(*) > 1;

when i execute this query on our server it work fine. but on the server of my customer i get the oracle error ORA-00979: not a GROUP BY expression.

As far i found out that im having problems with the Case's and with the alias.
with out this it works.

any suggestions?

*what i'm trying to do with this statement is to get all double entry's. with the inner query i change all old codes to the new one, and then i want to group them to see if they exists multiply times.
Some customers did used old codes and now its possible that they have the same town 2 times.

edit

SELECT * FROM product_component_version

and i get on both:

Product                                     Version         Status

NLSRTL                                      10.2.0.4.0      Production
Oracle Database 10g Enterprise Edition      10.2.0.4.0      64bi
PL/SQL                                      10.2.0.4.0      Production
TNS for 64-bit Windows:                     10.2.0.4.0      Production

edit2

my test showed me that he doesn't like calling with the alias.
is there a setting, that alias are not recognized?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

夏末的微笑 2025-01-02 06:37:19

“当我在我们的服务器上执行此查询时,它工作正常。但是在
我客户的服务器出现 oracle 错误 ORA-00979: not a GROUP
BY 表达式。
"

这意味着以下两种情况之一:

  1. 您的服务器与客户的服务器不同,并且这种差异可以防止错误;例如,您的服务器是更高版本或具有不同的补丁级别。
  2. 您不在事实上,在您的客户数据库上运行与您自己的数据库相同的代码

似乎很可能,因为您在此处发布的代码显然不是您在自己的服务器上运行的代码。已经指出,它包含一些语法错误,尽管两者都不会事实上,

该错误意味着您在投影中有一个非聚合列,该列不在 GROUP BY 子句中,或者您在 GROUP BY 子句中有某些内容不在投影中。

"when i execute this query on our server it work fine. but on the
server of my customer i get the oracle error ORA-00979: not a GROUP
BY expression.
"

This means one of two things:

  1. Your server is different from your customer's server and that difference prevents an error; for example, your server is a later version or has a different patch level.
  2. You are not in fact running the same code on your customer's database as you run on your own.

The latter seems quite likely, as the code you posted here obviously isn't the code you run on your own server. As others have pointed out, it contains a couple of syntax errors although neither would in fact hurl ORA-00979.

That error means you have a non-aggregate column in the projection which isn't in the GROUP BY clause or perhaps you have something in the GROUP BY clause which isn't in the projection.

深居我梦 2025-01-02 06:37:19

表名后面缺少括号,attribut15 后面缺少逗号。试试这个:

Select attribut1, dateattribut, attribut3, 
       attribut4, attribut15, town_CODE, count(*)     
from (
select attribut1, dateattribut, attribut3, attribut4, attribut15, (CASE 
  WHEN  TO_CHAR(dateattribut,'YYYY')  = '2005'  THEN 
   CASE town_CODE 
    WHEN '039' THEN  '078' WHEN '050' THEN  '093' 
    WHEN '091' THEN  '008' WHEN '102' THEN  '093' 
   ELSE town_CODE end 
  ELSE town_CODE end) as town_CODE
from towntable) GROUP BY attribut1, dateattribut, 
                        attribut3, attribut4, 
                        attribut15, town_CODE
having count(*) > 1;

You are missing a bracket after the table name plus a comma after attribut15. Try this:

Select attribut1, dateattribut, attribut3, 
       attribut4, attribut15, town_CODE, count(*)     
from (
select attribut1, dateattribut, attribut3, attribut4, attribut15, (CASE 
  WHEN  TO_CHAR(dateattribut,'YYYY')  = '2005'  THEN 
   CASE town_CODE 
    WHEN '039' THEN  '078' WHEN '050' THEN  '093' 
    WHEN '091' THEN  '008' WHEN '102' THEN  '093' 
   ELSE town_CODE end 
  ELSE town_CODE end) as town_CODE
from towntable) GROUP BY attribut1, dateattribut, 
                        attribut3, attribut4, 
                        attribut15, town_CODE
having count(*) > 1;
扶醉桌前 2025-01-02 06:37:19

原始查询中似乎存在一两个语法错误 - 以下内容应该有效:

Select attribut1, 
       dateattribut, 
       attribut3, 
       attribut4, 
       attribut15, 
       town_CODE, 
       count(*)     
from (select attribut1, 
             dateattribut, 
             attribut3, 
             attribut4, 
             attribut15,
             CASE WHEN TO_CHAR(dateattribut,'YYYY') = '2005' THEN 
                  CASE town_CODE 
                       WHEN '039' THEN  '078' 
                       WHEN '050' THEN  '093' 
                       WHEN '091' THEN  '008' 
                       WHEN '102' THEN  '093' 
                       ELSE town_CODE
                  end 
                  ELSE town_CODE
             end as town_CODE
      from towntable) v 
GROUP BY attribut1, 
         dateattribut, 
         attribut3, 
         attribut4, 
         attribut15, 
         town_CODE
having count(*) > 1

There appear to be one or two syntax errors in the original query - the following should work:

Select attribut1, 
       dateattribut, 
       attribut3, 
       attribut4, 
       attribut15, 
       town_CODE, 
       count(*)     
from (select attribut1, 
             dateattribut, 
             attribut3, 
             attribut4, 
             attribut15,
             CASE WHEN TO_CHAR(dateattribut,'YYYY') = '2005' THEN 
                  CASE town_CODE 
                       WHEN '039' THEN  '078' 
                       WHEN '050' THEN  '093' 
                       WHEN '091' THEN  '008' 
                       WHEN '102' THEN  '093' 
                       ELSE town_CODE
                  end 
                  ELSE town_CODE
             end as town_CODE
      from towntable) v 
GROUP BY attribut1, 
         dateattribut, 
         attribut3, 
         attribut4, 
         attribut15, 
         town_CODE
having count(*) > 1
仅此而已 2025-01-02 06:37:19

我的解决方案是使用视图。

内部选择为视图,然后外部正常选择,效果很好。

我发现他不喜欢外部选择中的town_CODE。

Select attribut1, dateattribut, attribut3,
       attribut4, attribut15, town_CODE, count(*)     
from  v_towntable
GROUP BY attribut1, dateattribut, attribut3, 
         attribut4, attribut15, town_CODE
having count(*) > 1

My solution is to use an View.

Inner Select as View and then the outer select as normal, and it works fine.

i found out that he doesn't like town_CODE in the outer select.

Select attribut1, dateattribut, attribut3,
       attribut4, attribut15, town_CODE, count(*)     
from  v_towntable
GROUP BY attribut1, dateattribut, attribut3, 
         attribut4, attribut15, town_CODE
having count(*) > 1
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文