这个mysql查询的laravel查询生成器代码是什么;
SELECT * FROM Student WHERE family_id IN (SELECT family_id FROM students GROUP BY family_id HAVING COUNT(1)>1) ORDER BY family_id
jhiyze9q1#
在where子句中使用函数:
Student::whereIn('family_id', function($query) { $query->select('family_id') ->from(with(new Students)->getTable()) ->groupBy('family_id') ->havingRaw('COUNT(1) > 1') })->get();
m3eecexj2#
$query = DB::select("SELECT * FROM Student WHERE family_id IN (SELECT family_id FROM students GROUP BY family_id HAVING COUNT(1)>1) ORDER BY family_id")
基于laravel文档
2条答案
按热度按时间jhiyze9q1#
在where子句中使用函数:
m3eecexj2#
基于laravel文档