平均计算codeigniter查询
Averge calculation codeigniter query
我正在尝试查找平均速率,但低于 codeigniter 查询结果错误 "Unknown column 'prate' in 'field list'"
$this->db->select('AVG(prate)as avgprate');
$this->db->from('stock','(select sum((pdetails.quantity*pdetails.rate)/pdetails.quantity) AS prate FROM `stock` INNER JOIN `pdetails` ON `pdetails`.`stock_id` = `stock`.`stock_id`)');
$result = $this->db->get();
$res = $result->row();
我该如何解决这个问题
$this->db->select('AVG(t.prate)as avgprate');
$this->db->from('stock ,(select sum((pdetails.quantity*pdetails.rate)/pdetails.quantity) AS prate FROM `stock` INNER JOIN `pdetails` ON `pdetails`.`stock_id` = `stock`.`stock_id`)t');
$result = $this->db->get();
$res = $result->row();
我正在尝试查找平均速率,但低于 codeigniter 查询结果错误 "Unknown column 'prate' in 'field list'"
$this->db->select('AVG(prate)as avgprate');
$this->db->from('stock','(select sum((pdetails.quantity*pdetails.rate)/pdetails.quantity) AS prate FROM `stock` INNER JOIN `pdetails` ON `pdetails`.`stock_id` = `stock`.`stock_id`)');
$result = $this->db->get();
$res = $result->row();
我该如何解决这个问题
$this->db->select('AVG(t.prate)as avgprate');
$this->db->from('stock ,(select sum((pdetails.quantity*pdetails.rate)/pdetails.quantity) AS prate FROM `stock` INNER JOIN `pdetails` ON `pdetails`.`stock_id` = `stock`.`stock_id`)t');
$result = $this->db->get();
$res = $result->row();