SELECT VendorName, COUNT(*) as Total_Invoices
FROM Invoices JOIN Vendors ON Invoices.VendorID = Vendors.VendorID
WHERE Vendors.VendorName = 'IBM'
GROUP BY VendorName
ORDER BY Total_Invoices DESC
会出现
VendorName Total_Invoices
IBM 2
我想这样做只是说
Total_Invoices
2
未显示IBM VendorName,但仍在计算IBM的总发票
答案 0 :(得分:4)
您可以安全地删除此案例中的VendorName
。
SELECT COUNT(*) as Total_Invoices
FROM Invoices JOIN Vendors ON Invoices.VendorID = Vendors.VendorID
WHERE Vendors.VendorName = 'IBM'
GROUP BY VendorName
ORDER BY Total_Invoices DESC
另一方面, select
也称为投影。你可以安全地删除它而不会造成任何伤害。但是在GROUP BY
子句中删除它是一个非常不同的事情。
答案 1 :(得分:3)
您只需清除VendorName
中的Select
即可。
在这种情况下,您无需使用GROUP BY
或ORDER BY
SELECT COUNT(*) as Total_Invoices
FROM Invoices JOIN Vendors ON Invoices.VendorID = Vendors.VendorID
WHERE Vendors.VendorName = 'IBM'
答案 2 :(得分:1)
从SELECT中删除VendorName。