-1
我有銷售,車輛和客戶的表格,我正在嘗試創建一個查詢,該查詢可以給出購買該類型車輛的客戶的姓名和姓名。我創建了下面的子查詢找到降序汽車銷售:SQL Developer查詢
SELECT Vehicles.Vehicle_Make,
COUNT(Sales.VIN) AS NumberOfSales
FROM Sales
INNER JOIN Vehicles ON Sales.VIN = Vehicles.VIN
GROUP BY Vehicles.Vehicle_Make
ORDER BY NumberOfSales DESC;
和銷售客戶情況表有着共同的cust_id列從中我能得到客戶名和姓。由於第一行會給我最賣車的牌子,我如何查詢第一行並將這個子查詢的結果加入到客戶表中以獲取名字和姓氏?預先感謝您的建議。
MySQL或SQL服務器? – SqlZim
SQL Server和'LIMIT 1'的TOP 1' - 具有適當的ORDER BY'的mySQL,用於 –
SELECT TOP 1 Vehicles.Vehicle_Make, COUNT(Sales.VIN)AS NumberOfSales FROM Sales INNER JOIN車輛銷售.VIN = Vehicles.VIN GROUP BY Vehicles.Vehicle_Make ORDER BY NumberOfSales DESC; –