2

是否可以将 SQL ServerOUTER APPLY与 Codeignter 的 Active Record 一起使用?

4

2 回答 2

1

不可能。要使用 Cross Apply 或 Outer Apply,您需要在文件 system\database\DB_query_builder.php 中添加特定函数

话虽如此,您可以将此功能(从 join one 修改)添加到所述文件:

public function apply($table, $type = '', $escape = NULL){
    if ($type !== '')
    {
        $type = strtoupper(trim($type));

        if ( ! in_array($type, array('CROSS', 'OUTER'), TRUE))
        {
            $type = 'CROSS';
        }
    }
    else{
        $type = 'CROSS';
    }

    // Extract any aliases that might exist. We use this information
    // in the protect_identifiers to know whether to add a table prefix
    $this->_track_aliases($table);

    is_bool($escape) OR $escape = $this->_protect_identifiers;

    // Do we want to escape the table name?
    if ($escape === TRUE)
    {
        $table = $this->protect_identifiers($table, TRUE, NULL, FALSE);
    }

    // Assemble the APPLY statement
    $this->qb_join[] = $join = $type.' APPLY '.$table;

    if ($this->qb_caching === TRUE)
    {
        $this->qb_cache_join[] = $join;
        $this->qb_cache_exists[] = 'join';
    }

    return $this;
}

然后,您可以像使用它一样使用它

$this->db->apply('(select * from table_a where table_a.id=table_z.fk_id) as tmp_table');

或者更完整的东西,比如

$this->db->apply('(select * from table_a where table_a.id=table_z.fk_id) as tmp_table','outer',false);
于 2021-01-28T03:53:05.457 回答
0

你可以这样做

$this->db->join('comments', 'comments.id = blogs.id', 'outer');

或者

$this->db->query("SELECT column_name(s)
    FROM table1
    FULL OUTER JOIN table2
    ON table1.column_name=table2.column_name;");

01

Codeigniter 查询生成器OUTER APPLY示例


可能与 Codeigniter 连接
(与 this 关联$this->db->join('comments', 'comments.id = blogs.id', 'outer');

  1. 剩下
  2. 正确的
  3. 左外
  4. 右外
于 2016-01-18T13:08:15.147 回答