How to use groupby having with DB::raw in Laravel Query Builder? (ok)
https://www.itsolutionstuff.com/post/how-to-use-groupby-having-with-dbraw-in-laravel-query-builderexample.html
Last updated
https://www.itsolutionstuff.com/post/how-to-use-groupby-having-with-dbraw-in-laravel-query-builderexample.html
Last updated
Đọc bài viết này đã có dữ liệu test (tương ứng ví dụ 1)
By Hardik Savani July 6, 2016 Category : LaravelPlayUnmuteLoaded: 1.17%Fullscreen
We most probably require to use group by having because if you work on small project then it's not need to use generally. But if you work with big project like e-commerce, social or ERP level project then you may require to use having clause.
you can also use groupby having with db raw in laravel 6, laravel 7, laravel 8 and laravel 9 app.
having clause, we can use simply if we have to compare with number or static value like as bellow:
But we need to compare with 10 instead of column name then it can't directly use column name. At that time we should use DB::raw() with column name.
In this example i want to show minimum quantity items, I have two tables one items and another one items_count both mysql table layout is here:
items table:
items_count table:
I need to get that product has less quantity to min_quantity of items table, so we check get that items using bellow query:
Example
You will find bellow output get only items no. 2.
Read Also: How to use groupby having with DB::raw in Laravel Query Builder?