id sm_id to_id
1 3 2
2 4 1
3 3 3
4 3 2
5 3 3
6 4 1
如何計算 sm_id
有多少次出現?使用laravel比較和計數兩個表格
我有兩個輸入,第一個sm_id
和第二個to_id
,我想根據輸入計數值的發生。
爲sm_id = 4 and to_id = 1
預期的結果將是2
這裏是我試過
$us = \DB::table('mgs')
->where('sm_id', '=', DB::raw('to_id'))
->where('to_id', '=', DB::raw('sm_id'))
->groupBy('sm_id')
->count();
print_r($us);die;
這樣一個愚蠢的問題,謝謝@alexey –
很高興它有幫助。 –