SELECT *, FROM location WHERE date IN (SELECT MAX(date)
FROM location GROUP BY user detail id);
我已经为上述代码编写了代码,但是没有用。这是代码:
$this->db->order_by("date","desc");
$select= $this->db->select('*');
$this->db->group_by('userdetail_id');
$this->db->limit(1); $qry = $this->db->get('location');
答案 0 :(得分:0)
您可以按照以下方式写
$this->db->select('*');
$this->db->where("date IN (SELECT MAX(date) FROM location GROUP BY userdetail_id) ",false,false);
$this->db->limit(1);
$this->db->order_by("date","desc");
$qry = $this->db->get('location');
答案 1 :(得分:0)
查询应为:
$this->db->select("*");
$this->db->where_in("(SELECT MAX(date) FROM location GROUP BY userdetail_id)");
$this->db->order_by("date","desc");
$this->db->get('location')