COUNT 在 PHP 的 db2 中导致错误

发布于 2024-12-07 17:02:00 字数 644 浏览 0 评论 0原文

当我运行此查询时,出现以下错误:

Column MANUFACTURER or expression in SELECT list not valid.

如果删除 COUNT 函数,查询将正常运行。

有什么想法吗?

(此查询有点模拟,因此可能没有完全意义)

SELECT
  MANUFACTURER
, PART_NUMBER
, COUNT(1) AS CNT
FROM 
( SELECT
    AWPART AS PART_NUMBER  
  , MANF AS MANUFACTURER       
  FROM STKMP                        
    INNER JOIN PRICING AS P         
      ON AWPART = P.JCPART  
      AND R.CODE = 1        
    WHERE  PART_NUMBER LIKE '%A2%') AS T 

按如下方式修改最后一行会产生相同的效果。

WHERE  PART_NUMBER LIKE '%A2%') AS T  GROUP BY MANUFACTURER              

When I run this query I get the following error:

Column MANUFACTURER or expression in SELECT list not valid.

The query runs fine if I remove the COUNT function.

Any ideas?

(this query is a bit of a mock so it might not make perfect sense)

SELECT
  MANUFACTURER
, PART_NUMBER
, COUNT(1) AS CNT
FROM 
( SELECT
    AWPART AS PART_NUMBER  
  , MANF AS MANUFACTURER       
  FROM STKMP                        
    INNER JOIN PRICING AS P         
      ON AWPART = P.JCPART  
      AND R.CODE = 1        
    WHERE  PART_NUMBER LIKE '%A2%') AS T 

Modifying the last line as follows produces the same effect.

WHERE  PART_NUMBER LIKE '%A2%') AS T  GROUP BY MANUFACTURER              

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

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

发布评论

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

评论(1

破晓 2024-12-14 17:02:00

通常,只有当您有 GROUP BY 子句时,COUNT() 才有意义。也许您想将其添加到末尾(在 AST 之后?):

GROUP BY MANUFACTURER, PART_NUMBER;

Typically COUNT() is only meaningful if you have a GROUP BY clause. Perhaps you meant to add this to the end (after the AS T?):

GROUP BY MANUFACTURER, PART_NUMBER;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文