嗨,我正在使用mysql
ROUND
和AVG
功能,
public function get_average_rating_by_specialty($shop_id,$where_array=array())
{
$this->replica->select('PreferenceToLOBID,PreferenceID , AVG(ROUND(AvarageRating)) as AvarageRating');
$this->replica->from('*******');
$this->replica->where(array('ShopID'=>$shop_id,'IsDelete'=>0));
if($where_array)
{
$this->replica->where($where_array);
}
$this->replica->group_by('PreferenceID,PreferenceToLOBID');
$result = $this->replica->get();
return $result->result_array();
}
这里我试图在四舍五入后得到平均值AvarageRating
,
我在该行中只有一条符合我的条件的记录,AvarageRating
值为 4.5
但查询结果是
Array
(
[0] => Array
(
[PreferenceToLOBID] => 29
[PreferenceID] => 654
[AvarageRating] => 4.0000
)
)
当我删除ROUND
它时,它可以正常工作,但我想AvarageRating
在得到平均值之前对值进行四舍五入
在这种情况下,我希望 4.5 是结果,为什么它返回 4
请帮助,在此先感谢。