2017-07-16 77 views
-5
  1. 我想要一個結果集,會告訴我由供應商分組的發票。
  2. 我想要一個結果集,會告訴我的供應商,他們已經爲了開發票從最低金額開具發票發票量最多的總量。
  3. 我想要的結果集,其中顯示了一個總金額超過$ 2000.00更大的供應商,他們已開具發票的總金額。
Select * from Invoices group by VendorID; 

Select Vendors.VendorID,Vendors.VendorName,sum(Invoices.InvoiceTotal) 
from Vendors inner join Invoices on Vendors.VendorID = Invoices.VendorID group by Vendors.VendorID order by sum(Invoices.InvoiceTotal); 


Select Vendors.VendorID,Vendors.VendorName,sum(Invoices.InvoiceTotal) 
from Vendors inner join Invoices on Vendors.VendorID = Invoices.VendorID group by Vendors.VendorID having sum(Invoices.InvoiceTotal) > 2000; 

此代碼給了我同樣的錯誤:需要幫助搞清楚什麼是錯我的代碼

Msg 8120, Level 16, State 1, Line 2

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

Msg 8120, Level 16, State 1, Line 4

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

Msg 8120, Level 16, State 1, Line 8

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

+0

請出示你到目前爲止試圖解決這個問題。請參閱[如何調試小程序(https://ericlippert.com/2014/03/05/how-to-debug-small-programs/)。 – Xufox

+1

請編輯你的問題,並給它一個有意義的標題。大家誰問了一個問題在這裏_Need幫助搞清楚什麼是錯我的code_ – baao

回答

0

嘗試讓子查詢的連接

Select * from 
(Select Vendors.VendorID, Vendors.VendorName, sum(Invoices.InvoiceTotal) as total 
from Vendors inner join Invoices on Vendors.VendorID = Invoices.VendorID) 
as T1 group by T1.VendorID order by T1.total; 
+0

請接受的解決方案,如果您滿意 –

0

#1:對我來說由分組供應商可能意味着order by vendorID或者更可能的一種簡單COUNT

#2 & 3:你要添加Vendors.VendorNameGROUP BY列表

相關問題