For some reason, I must be missing something when I am trying to move my query from raw SQL to Laravel DB.
At the moment, with this SQL query:
SELECT id, COUNT(id) AS count FROM agent_billings_items WHERE agentBillingBatch = 224 AND shipmentID IS NOT NULL GROUP BY shipmentID HAVING COUNT(id) > 1;
I get three (3) results back with the count return set correctly. However, when I try and write this out using Laravel DB:
$results = DB::table('agent_billings_items')
->select('id', DB::raw('count(*) as count'))
->where('agentBillingBatch', $this->id)
->whereNotNull('shipmentID')
->whereNull('deleted_at')
->groupBy('shipmentID')
->havingRaw('count > 1')
->get();
I get nothing returned. I know the raw SQL query is correct as I have manually checked it, so I know the $results in Laravel should come back with something.
I'd appreciate any help. Thanks
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire