0

我找不到让它工作的方法。我必须表格,第一个带有订单,第二个带有跟踪。我想将最新的跟踪行添加到左表行。这是我迄今为止尝试过的(不起作用):

        $this->db->select('orders.*, trackings.id AS trackings_id, trackings.order_id AS trackings_order_id, MAX(trackings.status) AS trackings_status, trackings.created_at AS trackings_created_at, trackings.updated_at AS trackings_updated_at, trackings.ip_address AS trackings_ip_address');
        $this->db->from('orders');
        $this->db->join('trackings', 'orders.id = trackings.order_id', 'left');
        $this->db->group_by('trackings.order_id');
        $this->db->order_by('orders.created_at', 'DESC');
        $query = $this->db->get();
        return $query->result();
4

1 回答 1

2

Woooh,我讨厌CI的活跃记录,这在大多数时候都是一个真正的痛苦......

首先,我会按orders.id 分组

其次,如果你定义“不工作”会很棒(给出错误的结果?根本不执行?)

PS很抱歉将其发布为答案(我更喜欢评论),但我的代表仍然有点低......

于 2013-06-20T18:19:13.853 回答