Iam尝试查找费率的平均值,但在codeignier查询结果下方出现错误““字段列表”中的未知列“ prate””
$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();