【问题标题】:I want to change this mySQL to a Laravels ORM我想将此 mySQL 更改为 Laravel ORM
【发布时间】:2019-05-02 16:10:41
【问题描述】:

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; 

【问题讨论】:

  • 你试过了吗?
  • 告诉我们你到目前为止尝试了什么......
  • $check_point = Vote_check::where('item_id', $item[0]->vote_checks->vote_id)->first(); ///////////////////////////////////////// //$chk_point = DB::table('vote_checks') ->join('vote_checks', function($join) { $join->on('vote_checks.item_id', '=', 'vote_items.id') ; })->where('vote_items.vote_id', $board)->select('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

标签: php mysql laravel


【解决方案1】:

试试这个方法:

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(); 

【讨论】:

    猜你喜欢
    • 2021-12-29
    • 2023-03-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-10
    相关资源
    最近更新 更多