我正在尝试从Vendors表中将一个Column作为“VendorName”,并从Invoices表的InvoiceTotal列中将一列作为InvoiceAverage。我正在尝试对表格中每个供应商的发票总额进行平均
SELECT InvoiceTotal
FROM Invoices
GROUP BY Invoices.InvoiceTotal
ORDER BY AVG(InvoiceTotal)
就我所知,并没有给我任何我想要的东西
答案 0 :(得分:1)
假设您加入了VendorId字段:
SELECT v.VendorName, AVG(i.InvoiceTotal) AS InvoiceAverage
FROM Invoices i
JOIN Vendors v ON i.VendorId = v.VendorId
GROUP BY v.VendorName
ORDER BY AVG(i.InvoiceTotal)
答案 1 :(得分:0)
select VendorName, avg(InvoiceTotal) as 'some column name'
from Invoices
group by VendorName
-- order by avg(InvoiceTotal) desc/ asc
您希望按平均值进行分组。这就是它的工作原理。