en....一个车辆下面关联司机个数,以及实现如图展示:
sql解决方法:
SELECT
bv.id AS id,
bv.status AS `status`,
GROUP_CONCAT(bd.driver_name) AS driverName,
LENGTH(GROUP_CONCAT(bd.driver_name)) - LENGTH(
REPLACE(
GROUP_CONCAT(bd.driver_name),‘,‘,‘‘)) + 1 AS countName,
GROUP_CONCAT(bd.driver_mobile) AS driverMobile
FROM
zcwl_b_vehicle bv
LEFT JOIN zcwl_b_driver_vehicle dv ON bv.id = dv.vehicle_id
LEFT JOIN zcwl_b_driver bd ON dv.driver_id = bd.id
WHERE
bv.id IN
(SELECT
zbv.id AS id
FROM
zcwl_b_vehicle zbv
LEFT JOIN zcwl_b_vehicle_user zbdv ON zbv.id = zbdv.vehicle_id
LEFT JOIN zcwl_user_info zui ON zbdv.user_result_id = zui.user_result_id
WHERE zui.user_result_id = #{param.userResultId}
)
GROUP BY bv.vehicle_license_plate_number
order by bv.create_time desc