2017-07-16 78 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列表

相关问题