我有这样的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?
请建议。
由于
答案 0 :(得分:1)
你需要一个小组
SELECT FORM_NO, SUM(QTY) as QTY
FROM SEIAPPS_QTY
WHERE FORM_NO = '1'
AND STATUS_QTY='OK'
GROUP BY FORM_NO
-Or -
由于您选择的是单个表单,因此可以删除表单编号
SELECT SUM(QTY) as QTY
FROM SEIAPPS_QTY
WHERE FORM_NO = '1'
AND STATUS_QTY='OK'
-Or -
如果您真的想在结果中使用单个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
答案 1 :(得分:0)
SELECT FORM_NO, SUM(QTY) as QTY FROM SEIAPPS_QTY WHERE FORM_NO = '1' AND STATUS_QTY='OK'
GROUP BY FORM_NO;
答案 2 :(得分: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
答案 3 :(得分:0)
试试这个,
SELECT FORM_NO, SUM(QTY) QTY
FROM SEIAPPS_QTY
WHERE FORM_NO = '1'
AND STATUS_QTY='OK'
GROUP BY form_no;
或者您可以尝试将qty
form_no = 1
与SELECT SUM(qty) QTY
FROM SEIAPPS_QTY
WHERE FORM_NO = '1'
AND STATUS_QTY='OK';
的总和相加
{{1}}