Php 我想把这个mySQL改成Laravels ORM
MySQL查询:Php 我想把这个mySQL改成Laravels ORM,php,mysql,laravel,Php,Mysql,Laravel,MySQL查询: select count(distinct vote_checks.user_id) AS count from vote_checks join vote_items on vote_checks.item_id=vote_items.id where vote_items.vote_id = 3; 试着这样做: DB::table('vote_checks') ->select(DB::raw('COUNT(DISTINCT v
select
count(distinct vote_checks.user_id) AS count from vote_checks
join
vote_items on vote_checks.item_id=vote_items.id
where
vote_items.vote_id = 3;
试着这样做:
DB::table('vote_checks')
->select(DB::raw('COUNT(DISTINCT vote_checks.user_id) as count')
->leftJoin('vote_items','vote_checks.item_id', '=', 'vote_items.id')
->where('vote_items.vote_id',3)
->get();
你试过什么了吗?告诉我们到目前为止你试过什么…$check\u point=Vote\u check::where('item\u id',$item[0]->Vote\u checks->Vote\u id)->first()////////////////////////////////////////////////////$chk_point=DB::table('vote_checks')->join('vote_checks',function($join){$join->on('vote_checks.item_id','=','vote_items.id');})->其中('vote_items.vote_id',$board)->选择('vote_checks.user_id')->distinct()->count////$chk_point=Vote_check::where(,$board)->get()//distinct()->count('user_id')//$chk_point=Vote_check::where('item_id','1'->Vote_item->Vote_id)->get();对不起,我先用stackoverflow