2016-03-28 211 views
-3

如何在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 
+0

原始查詢這些類型的查詢可以使用whereRaw() –

+0

沒有得到結果。我想使用這個基於t_id的過濾器。如果多個t_id包含相同的u_id,那麼它應該是打印。 – Ankit

回答

0

可以鏈where條件與口才,每一個鏈評價像and

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

編輯:如果你需要的那些與U_ID一致認爲這樣的:

$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'); 
+0

我想根據t_id將其用於過濾器。如果多個t_id包含相同的u_id,那麼它應該是打印。一次可能有多個t_id 2或4,我該如何檢查? – Ankit

+0

vivoconunxino:我想u_id列表不是t_id。我是laravel的乞丐。如果t_id(11,21)相同u_id那麼我需要那個u_id。 – Ankit

+0

請檢查並嘗試編輯 – vivoconunxino