拜托,我想让这个问题有说服力,但我不知道如何制作。
我想将计数与分组依据一起使用,并按 count desc
排序->groupBy('room_id')->get();
但我不能。
这是我的原始查询:
SELECT * , count(seeker_id) FROM `jobs_skills` WHERE ( skill_id =2 OR skill_id =3 OR skill_id=5) group by seeker_id ORDER BY count(seeker_id) DESC
我花了很多时间来解决它,但我不能这样做。
请帮帮我。
答案 0 :(得分:0)
试试这个。如果在select中添加*,请确保在groupBy语句中包含额外字段。
$skills = JobsSkills::selectRaw('skill_id, count(seeker_id) as count')
->where('skill_id', 2)
->orWhere('skill_id', 3)
->orWhere('skill_id', 5)
->groupBy('seeker_id')
->orderBy('count', 'DESC')
->get();