动态分配值类型,其中查询不起作用,显示错误“数据库错误”'where子句'中的未知列'avgRateVal'。什么是最好的可能,任何建议
$this->db->select('round(avg(ratevalue),1) as avgRateVal');
if($minRating!=0)
$this->db->where('avgRateVal >=', 1);
if($maxRating!=0)
$this->db->where('avgRateVal <=', 5);
答案 0 :(得分:1)
您只能在GROUP BY,ORDER BY或HAVING子句中使用列别名。
像这样写下你的查询:
$this->db->select('round(avg(ratevalue),1) as avgRateVal');
if($minRating!=0)
$this->db->having('avgRateVal >=', 1);
if($maxRating!=0)
$this->db->having('avgRateVal <=', 5);
$this->db->get('Table_Name');
$this->db->result_array();
答案 1 :(得分:0)
$ this-&gt; db-&gt;选择(&#39; round(avg(ratevalue),1)as avgRateVal&#39;);
如果($ minRating!= 0)
$this->db->where('round(avg(ratevalue),1) >=', 1);
如果($ maxRating!= 0)
$this->db->where('round(avg(ratevalue),1) <=', 5);