0

这可能吗 ?表上的一列中的两列?

$this->db->select('header.*,customer.*,destination.location');
$this->db->from(self::WAYBILL_HEADER_TABLE. " as header");
$this->db->join(self::CUSTOMER_TABLE." as customer","header.consignee = customer.id");
$this->db->join(self::WAYBILLDESTINATION_TABLE. " as destination","header.destination_from = destination.id",'INNER');

$this->db->join(self::WAYBILLDESTINATION_TABLE. " as destinations","header.destination_to = destinations.id",'INNER');
$this->db->where('header.waybilldate <=',$date_to);
$this->db->where('header.waybilldate >=',$date_from);
$this->db->order_by('header.waybillno','DESC');
$query = $this->db->get()->result();
return $query;
4

4 回答 4

0

尝试这个

 $this->db->join('t2', 't1.x = t2.c', 'left');
于 2013-09-30T07:27:22.800 回答
0

您的问题不清楚,但要将两列合二为一,您可以在这样的选择语句中使用CONCAT函数

$this->db->select('table_name.column1, CONCAT(table_name.column2, ' ', table_name.column3) as table_name.twoInOne');

这只是一个如何使用concat函数的想法。另外,对于组 concat 检查这个答案

于 2013-09-30T07:40:18.690 回答
0

我建议在同一个表中加入两个或更多列:

    $this->db->select("*");
    $this->db->from("follows");
    $this->db->join('users table1','table1.user_id=follows.following_id','left');
    $this->db->join('users table2','table2.user_id=follows.follower_id','left');
    $this->db->where("table1.is_active",1);
    $this->db->where("table2.is_active",1);
    $res=$this->db->get();
    return $res->result();
于 2019-08-16T07:48:44.753 回答
0

尝试:

$this->db->query("SELECT CONCAT(column1,' ',column2) FROM employee_tbl");

该解决方案在 http://www.tutorialspoint.com/mysql/mysql-concat-function.htm中描述

于 2016-01-27T09:41:44.173 回答