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();
我该如何解决这个问题
答案 0 :(得分:0)
$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();