0

我有这样的 SQL 语法:

SELECT FORM_NO, SUM(QTY) as QTY FROM SEIAPPS_QTY WHERE FORM_NO = '1' AND STATUS_QTY='OK'

但面临这样的错误问题:

ORA-00937: not a single-group group function

我看到了来自 FORM_NO 的错误,我怎样才能包含那个 FORM_NO ?

请指教。

谢谢

4

4 回答 4

1

你需要一个小组

SELECT FORM_NO, SUM(QTY) as QTY 
FROM SEIAPPS_QTY 
WHERE FORM_NO = '1' 
  AND STATUS_QTY='OK'
GROUP BY FORM_NO

-或者-

由于您选择的是单个表格,因此您可以删除表格编号

SELECT SUM(QTY) as QTY 
FROM SEIAPPS_QTY 
WHERE FORM_NO = '1' 
  AND STATUS_QTY='OK'

-或者-

如果您真的想要结果中的单个 FORM_NO,请使用任意聚合函数

SELECT MIN(FORM_NO) AS FORM_NO, SUM(QTY) as QTY 
FROM SEIAPPS_QTY 
WHERE FORM_NO = '1' 
  AND STATUS_QTY='OK'
GROUP BY FORM_NO
于 2013-09-24T12:20:03.297 回答
0
SELECT FORM_NO, SUM(QTY) as QTY FROM SEIAPPS_QTY WHERE FORM_NO = '1' AND STATUS_QTY='OK'
GROUP BY FORM_NO;
于 2013-09-24T12:17:17.217 回答
0

在 Oracle 中,您需要对要检索的值(不在组函数中)使用 GROUP BY:

SELECT FORM_NO, SUM(QTY) as QTY FROM SEIAPPS_QTY WHERE FORM_NO = '1' AND STATUS_QTY='OK' GROUP BY FORM_NO
于 2013-09-24T12:17:27.230 回答
0

像这样试试

SELECT FORM_NO, SUM(QTY) QTY
FROM   SEIAPPS_QTY 
WHERE  FORM_NO = '1' 
AND STATUS_QTY='OK'
GROUP BY form_no;

或者你可以试试这个来得到总和qtyforform_no = 1

SELECT SUM(qty) QTY
FROM   SEIAPPS_QTY 
WHERE  FORM_NO = '1' 
AND STATUS_QTY='OK';
于 2013-09-24T12:26:11.510 回答