如何在代码点火器中编写以下代码

时间:2018-06-22 11:38:41

标签: php

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');

2 个答案:

答案 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')