2013-09-30 43 views
-1

我需要幫助與SQL oracle,我的小組由於沒有工作,我正在一個shell,所以我沒有任何幫助。如何在Oracle上進行GROUP BY?

有人可以告訴我如何將這個下一個請求按noArticle分組。

SELECT Article.noArticle, quantite 
FROM Article LEFT JOIN LigneCommande ON Article.noArticle = LigneCommande.noArticle 
GROUP BY Article.noArticle 
/

謝謝

+1

你想要返回的數量是多少?它需要像sum(quantite)或count(quantite)這樣的東西。由於它在一個組中,因此您需要比字段更具體的條目。 –

+0

@JeanneBoyarsky謝謝你,你是對的,我需要量子的總和,它現在的工作再次感謝 – pharaon450

回答

1

您是按列分組,然後嘗試使用不是組級別的數字字段,它是記錄級別。分組依據是聚合,您必須使用聚合列(您正在按列分組的列或聚合函數,如sum,avg,count,max或min)。您需要彙總您的記錄級字段以便能夠在投影中使用它們(select子句)。舉一個例子,你的嘗試就像試圖獲得美國女性的頭髮顏色(當然,有許多美國女性,他們可能有不同的頭髮顏色,所以試圖獲得美國女性的價值是不自然和不明智的來自美國婦女組的頭髮顏色)。您的固定查詢如下:

SELECT Article.noArticle, sum(quantite) 
FROM Article LEFT JOIN LigneCommande ON Article.noArticle = LigneCommande.noArticle 
GROUP BY Article.noArticle 
0

對於我的情況,我需要的quantite的總和所以爲了使其工作,我增加SUM(quantite),然後我通過noArticle

分組
+0

並且改善了嗎? –

2

爲配合東西,這是正確的SQL。

SELECT Article.noArticle, sum(quantite) 
FROM Article LEFT JOIN LigneCommande ON Article.noArticle = LigneCommande.noArticle 
GROUP BY Article.noArticle