SELECT AVG(harian) a from (select harian from sla limit 2) b
以上是在海迪斯克尔执行的工作,
只是在下面尝试:
$rata2 = $this->db->query('SELECT AVG(harian) a from (select harian from sla limit 2) b');
但是,似乎没有输出,请帮忙,谢谢
// Sub Query
$this->db->select('harian')->from('sla')->limit(2);
$subQuery = $this->db->get_compiled_select();
// Main Query
$rata2 = $this->db->select('AVG(harian)')
->from($subQuery)
->get();
return $rata2;
或者,如果您想返回数组中的数据
// Sub Query
$this->db->select('harian')->from('sla')->limit(2);
$subQuery = $this->db->get_compiled_select();
// Main Query
$rata2 = $this->db->select('AVG(harian)')
->from($subQuery)
->get()
->toArray();
return $rata2;