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
列'Invoices.InvoiceID'在选择列表中无效,因为它 不包含在聚合函数或GROUP BY中 子句。
Msg 8120,Level 16,State 1,Line 4
列'Vendors.VendorName'在选择列表中无效,因为它 不包含在聚合函数或GROUP BY中 子句。
Msg 8120,Level 16,State 1,Line 8
列'Vendors.VendorName'在选择列表中无效,因为它 不包含在聚合函数或GROUP BY中 子句。
答案 0 :(得分: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;
答案 1 :(得分:0)
#1:对我来说按供应商分组可能意味着new VariableTable(vt)
或更可能意味着简单的order by vendorID
。
#2& 3:您必须将COUNT
添加到Vendors.VendorName
列表