Query Execution [closed]

2019-09-26 07: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');