2013-09-24 70 views
0

SUM列的表後列表我有這樣的SQL語法:SQL廣東話包括在SELECT語法

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

在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 
+0

不僅Oracle需要這個。任何ANSI SQL兼容的DBMS都可以。 –

+0

謝謝,它幫助了我...... :) –

0
SELECT FORM_NO, SUM(QTY) as QTY FROM SEIAPPS_QTY WHERE FORM_NO = '1' AND STATUS_QTY='OK' 
GROUP BY FORM_NO; 
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 
0

嘗試這樣,

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

或者你可以試試這個來獲得的總和爲form_no = 1

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