How we use SQL HAVING Clause
Syntax
SELECT column_name list
FROM table_name
WHERE condition
GROUP BY column_name list
HAVING condition
ORDER BY column_name list;
having
methods may be used to group the query results. The having
method's signature is similar to that of the where
method:
<?php
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\DB;//include this
class UserController extends Controller
{
public function index()
{
$users = DB::table('users')
->groupBy('first_name', 'status')
->having('account_id', '>', 100)
->get();
return view('user.index', ['users' => $users]);
}
}
?>