【发布时间】:2018-03-23 06:03:26
【问题描述】:
我要加入三个表并计算MY SQL FIDDLE。在这个查询中,我想再计算一个像total_trip 这样的计数,这意味着我已经加入了trip_details 表,在这个表中取出所有计数,即总行程计数,我无法编写子查询。
SELECT COUNT(T.tripId) as Escort_Count,
(
SELECT COUNT(*) FROM
(
SELECT a.allocationId
FROM escort_allocation a
INNER JOIN cab_allocation c ON a.allocationId = c.allocationId
WHERE c.allocationType = 'Adhoc Trip'
GROUP BY a.allocationId
) AS Ad
) AS Adhoc_Trip_Count
FROM
(
SELECT a.tripId FROM
trip_details a
INNER JOIN
escort_allocation b
ON a.allocationId = b.allocationId
GROUP BY a.allocationId
) AS T
【问题讨论】:
-
您究竟希望您的查询做什么?从您的陈述中不清楚,我想再算一次,比如
total_trip,这意味着我已经加入了trip_details表,在这个表中算出所有的总行程数。 -
期望的结果是什么?
-
@潜伏者。检查我的link。从这里我得到两个结果,如
Escort_Count和Adhoc_Trip_Count,现在我想再得到一个结果是total_trip,total_trip 意味着我们必须从trip_details表中计算* -
@ Stanislovas Kalašnikovas, Escort_Count:
5and Adhoc_Trip_Count:2and total_trip :7 -
更新您的问题(不发表评论)添加适当的数据样本和预期结果