How to use BETWEEN condition using using main query and sub queries

后端 未结 1 966
广开言路
广开言路 2021-01-29 13:00

I am using JOIN in 3 tables and getting the count and also mysql query working perfectly, now my question is I want to add one BETWEEN condition in my

相关标签:
1条回答
  • 2021-01-29 13:26

    You have to add WHERE clause to each sub-query in following:

      SELECT COUNT(T.tripId) as Escort_Count,
      (
          SELECT COUNT(*) FROM 
          (
              SELECT a.allocationId
              FROM escort_allocation a 
              INNER JOIN trip_details b ON a.allocationId = b.allocationId 
              INNER JOIN cab_allocation c ON a.allocationId = c.allocationId 
              WHERE c.allocationType = 'Adhoc Trip' AND tripDate BETWEEN '20180315' AND '20180320'
              GROUP BY a.allocationId
          ) AS Ad
    
      ) AS Adhoc_Trip_Count,
      (SELECT COUNT(id) FROM trip_details WHERE tripDate BETWEEN '20180315' AND '20180320') as Total_Count
      FROM 
      ( 
          SELECT a.tripId FROM 
          trip_details a 
          INNER JOIN 
          escort_allocation b 
          ON a.allocationId = b.allocationId 
          WHERE tripDate BETWEEN '20180315' AND '20180320'
          GROUP BY a.allocationId 
      ) AS T
    
    0 讨论(0)
提交回复
热议问题