I have 3 tables:
- Shifts {vehicled_id, user_id, subdriver_id)
- Users {user_id, subdriver_id)
- Vehicles {vehicle_id}
I want to group Shifts when I join with Users and Vehicles but some shifts only have user_id or subdriver_id and some have both.
This is the picture of shifts tables.
The result I want is a groupBy of vehicle_id and: If it has only user_id or subdriver_id it will return {user_id, vehicle_id, shift_id (it can be an array)} or {subdriver_id, vehicle_id, shift_id (it can be an array)}. If it has both user and subdriver it will return {user_id, vehicle_id, shift_id(it can be array)}
shift_id is based on user_id and vehicle_id or subdriver_id and vehicle_id.
How can I groupBy and return a result like this?