Query Execution [closed]

半世苍凉 提交于 2019-12-27 03:35:45

问题


How to execute this query in laravel. ?

  select d1.update_id from ( select update_id, count(update_id) 
  as ct from updates_tags where tag_id in (67,33,86,55) group by 
  update_id) as d1 where d1.ct=4

回答1:


you can use Raw Queries in Laravel

$results = DB::select(SELECT * FROM table WHERE id IN (1,2,3,4) AND );

http://fideloper.com/laravel-raw-queries




回答2:


You can chain where conditions with eloquent, each chained one is evaluated like an and.

$update = Tag::whereIn('t_id',$tags)->whereIn('u_id',$tags)->where(/*more and conditions you could need*/)->lists('u_id')

Edit: If you need the ones coincident with u_id consider this:

$update = DB::table('tags')
->select('t_id', 'u_id', DB::raw('count(*) as total'))
->whereIn('t_id',$tags)
->where('total','=',count($tags))
->groupBy('u_id')
->lists('u_id');


来源:https://stackoverflow.com/questions/36260657/query-execution

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!