Please I am trying to run a query that looks like this in raw sql
SELECT COUNT(cntr) count, address,
description FROM resti GROUP BY cntr = HAVING count > 1
in laravel.
I have tried this
DB::table("resti")
->select(DB::raw("COUNT(cntr) count, address, description"))
->groupBy("cntr")
->havingRaw("count > 1")
->get();
But it gives of some aggregate error.
Your SQL query should be like this
SELECT COUNT(cntr) count, address, description
FROM resti
GROUP BY cntr
HAVING COUNT(cntr) > 1
In Laravel your code should be like this
DB::table("resti")
->select(DB::raw("COUNT(cntr) count, address, description"))
->groupBy("cntr")
->havingRaw("COUNT(cntr) > 1")
->get();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With