I have two table both contains data around 200,000. I have write a query like below to retrieve data using some joins.
This is the query I have tried
$dbYTD = DB::table('stdtsum as a')
->join(DB::raw("(select distinct s_id, c_cod, compid from stdcus) b"), function($join){
$join->on('a.compid', '=', 'b.compid')->on('a.c_cod', '=', 'b.c_cod');
})
->select('b.s_id', DB::raw('sum(turnover) as sumturn'))
->whereBetween('date', [$startYTD, $endYTD])
->groupBy('b.s_id')
->get()
->toArray();
This query is giving result correct but the process time it takes is very long, sometimes it even timesout.
Can anybody help me how can I optimize this query?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire