我想運行此查詢,但它給我錯誤。計算子查詢select語句中的聚合值SQL
列'Order.OrderId'在選擇列表中無效,因爲它不包含在聚合函數或GROUP BY
子句中。
這裏是我的查詢:
SELECT vc.VehicleCategoryName,
(SELECT COUNT(oc.OrderId) FROM [Order] oc WHERE oc.OrderId = o.OrderId AND c.OrderStatusId = 2) AS completedTrip,
(SELECT COUNT(oc.OrderId) FROM [Order] oc WHERE oc.OrderId = o.OrderId AND oc.OrderStatusId = 3) AS CanceledTrip
FROM [Order] o
INNER JOIN VehicleCategory vc ON vc.VehicleCategoryId = o.VehicleCategoryId
WHERE CAST(o.OrderTime AS date) = '2017-03-13'
GROUP BY vc.VehicleCategoryName;
我想我的形成數據是這樣的:
VehicleCategoryName|Completed Trips | Canceled Trips
Bugdet 100 20
Premier 50 10
Rocket 20 20
請幫忙什麼是錯的,我用骨料在做什麼?
請不要使用JavaScript/HTML片段格式,除非它是Javascript或HTML或CSS – GrabNewTech
哪個DBMS您使用的?在你的問題中有非標準的SQL –