I am joining three tables and taking count MY SQL FIDDLE. In this query I want to take one more count like total_trip
that means I already join the trip_details
table, in this table take all count that is total trip count, I am not able to write sub query.
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