php – Eloquent选择每个不同的’id’中的第一个?
发布时间:2020-12-13 22:54:19 所属栏目:PHP教程 来源:网络整理
导读:我有一个带有字段district_id的员工表.我想要一个选择每个区的第一个员工的查询. 目前我手动硬编码: $tributes = [Employee::where('district_id','=' 1)-take(1)-get(),Employee::where('district_id','=' 2)-take(1)-get(),'=' 3)-take(1)-get(),...]; 只
我有一个带有字段district_id的员工表.我想要一个选择每个区的第一个员工的查询.
目前我手动硬编码: $tributes = [ Employee::where('district_id','=' 1)->take(1)->get(),Employee::where('district_id','=' 2)->take(1)->get(),'=' 3)->take(1)->get(),... ]; 只使用一次雄辩的电话就可以做到这一点吗?有志愿者吗? 解决方法
我不习惯laravel.但下面的内容可能有所帮助.一名员工需要分组,升序ID将确认第一名员工.
Employee::whereIn('district_id',array(1,2,3)) ->orderBy('employee_id','asc') ->groupBy('employee_id') ->get(); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |