I have query by elequent (Laravel): Service::select([ 'services.id', 'services.stoid',…
Rate quality
Private research annotation
Sign in to add a private research label or note.
- User
I have query by elequent (Laravel): Service::select([ 'services.id', 'services.sto_id',
code'services.category_id as category_id', "services.name->{$lang} as service_name", 'services.price as service_price', 'services.labour_hours as service_labour_hours' ]) ->where('services.sto_id', $stoId);I want join sto_service by service_id and sto_id, should joined max and min of sto_services.labour_hours
- Assistant
To join the
sto_servicetable with theservicestable based onservice_idandsto_id, and get the maximum and minimum ofsto_services.labour_hours, you can modify your query as follows:phpService::select([ 'services.id', 'services.sto_id', 'services.category_id as category_id', "services.name->{$lang} as service_name", 'services.price as service_price', 'services.labour_hours as service_labour_hours', DB::raw('MAX(sto_services.labour_hours) as max_labour_hours'), DB::raw('MIN(sto_services.labour_hours) as min_labour_hours') ]) ->join('sto_services', function($join) { $join->on('services.id', '=', 'sto_services.service_id') ->on('services.sto_id', '=', 'sto_services.sto_id'); }) ->where('services.sto_id', $stoId) ->groupBy('services.id') ->get();
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.