2014-12-03 71 views
-1

我正在處理庫存系統項目,我需要問一件事情,我如何擺脫這個問題,我寫一個SQL查詢,如下所示:列'ITEM_DETAILS.VENDOR_NAME'在選擇列表中無效,因爲它不包含在聚合函數或GROUP BY子句中

Select 
ITEM_DETAILS.VENDOR_NAME, 
LEDGER.VENDOR_NAME, 
ITEM_DETAILS.AMOUNT, 
LEDGER.CREDIT, 
(Sum(ITEM_DETAILS.AMOUNT)-LEDGER.CREDIT) 
as Balance From ITEM_DETAILS 
inner join LEDGER on ITEM_DETAILS.VENDOR_NAME=LEDGER.VENDOR_NAME 
where LEDGER.VENDOR_NAME='memon' 
Group by ITEM_DETAILS.VENDOR_NAME 

但是,當我試圖運行這個它給了我以下錯誤:

Column 'ITEM_DETAILS.VENDOR_NAME' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause. 

任何幫助將是非常可觀。

回答

1

試試這個:

您需要同時使用聚合函數添加列(比其他聚合函數)

Select 
ITEM_DETAILS.VENDOR_NAME, 
LEDGER.VENDOR_NAME, 
ITEM_DETAILS.AMOUNT, 
LEDGER.CREDIT, 
(Sum(ITEM_DETAILS.AMOUNT)-LEDGER.CREDIT) 
as Balance From ITEM_DETAILS 
inner join LEDGER on ITEM_DETAILS.VENDOR_NAME=LEDGER.VENDOR_NAME 
where LEDGER.VENDOR_NAME='memon' 
Group by ITEM_DETAILS.VENDOR_NAME, 
LEDGER.VENDOR_NAME, 
ITEM_DETAILS.AMOUNT, 
LEDGER.CREDIT, 
相關問題