zoukankan      html  css  js  c++  java
  • laraval join 的理解

    public function join($table, $one, $operator = null, $two = null, $type = 'inner', $where = false)
    {
    // If the first "column" of the join is really a Closure instance the developer
    // is trying to build a join with a complex "on" clause containing more than
    // one condition, so we'll add the join and call a Closure with the query.
    if ($one instanceof Closure) {
    $join = new JoinClause($type, $table);
    call_user_func($one, $join);
    $this->joins[] = $join;
    $this->addBinding($join->bindings, 'join');
    }
    // If the column is simply a string, we can assume the join simply has a basic
    // "on" clause with a single condition. So we will just build the join with
    // this simple join clauses attached to it. There is not a join callback.
    else {
    $join = new JoinClause($type, $table);
    $this->joins[] = $join->on(
    $one, $operator, $two, 'and', $where
    );
    $this->addBinding($join->bindings, 'join');
    }
    return $this;
    }

    ====DB::table('app_a as a')
    ->join('app_b as b',function($join){
    $join->on('a.id','=','b.goodId')
    ->where('b.status','=','SUCCESS')
    ->where('b.type','=','UNLOCK');
    }, null,null,'left')
    ->where('a.id','>',1)
    ->get();

    //相当于
    SELECT * FROM app_a as a
    LEFT JOIN app_b as b on a.id = b.goodId
    and b.status = 'SUCCESS' and b.type = 'UNLOCK'
    where a.id > 1;


    当join不传left时,默认是inner。

  • 相关阅读:
    v-date
    文字在图片上
    v-生命周期
    彭博接口分类
    如何指定vim 的查找是从上往下还是从下往上[z]
    查看linux版本
    git web找不到new project解决方法
    比特币运行原理[z]
    [Z]haproxy+keepalived高可用群集
    blockchain good article
  • 原文地址:https://www.cnblogs.com/JdsyJ/p/11357104.html
Copyright © 2011-2022 走看看