我有4张桌子
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)


它给了我null0
尝试了很多,但没有成功。
谢谢

最佳答案

we_vehicles.veh_status不能同时等于1和0。

或如以下评论所述:

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)
;


注意:我不确定您使用的JOIN是否一定适合您想要的最终结果,并且使用GROUP BY也可能合适。

关于php - 多重选择和INNER JOIN多重Where子句,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30221091/

10-09 00:43