I have 4 tables
we_vehicles_coordinates
we_vehicles
we_drivers
we_clients
SELECT mrk_lat,we_clients.client_id,mrk_lng ,engine_status ,created_date,live_fuel,
count(we_drivers.driver_id) as total_drivers,
count(we_vehicles.veh_id) as total_veh,
count(we_vehicles.veh_status) as run_veh,
count(we_vehicles.veh_status) as stop_veh
FROM `we_vehicles_coordinates`
INNER JOIN we_vehicles ON
we_vehicles.veh_id = we_vehicles_coordinates.veh_id
INNER JOIN we_drivers ON
we_drivers.veh_id = we_vehicles.veh_id
INNER JOIN we_clients ON
we_clients.client_id = we_vehicles.client_id
WHERE (we_vehicles.veh_status='1') AND
(we_vehicles.veh_status='0') AND
(we_clients.client_id= 3)
It gives me null
and 0
. Tried a lot but didn't got success.
Thanks
we_vehicles.veh_status
cannot equal 1 and 0 simultaneously.
or as it was put by a comment below:
SELECT /* stuff here */
, SUM(IF(we_vehicles.veh_status = 1, 1, 0) AS run_veh
, SUM(IF(we_vehicles.veh_status = 0, 1, 0) AS stop_veh
FROM /* more stuff */
WHERE (we_vehicles.veh_status in ('1','0') AND (we_clients.client_id= 3)
;
Note: I am not sure the JOINs you are using are necessarily appropriate for the final result you want, and using a GROUP BY
might be appropriate as well.
根据您的表和您想要的东西,我建议不要使用join
使用union
(如果要复制行,请使用union all
)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.