FLOOR()、GROUP
处理
在此,整理一下,还请指教…
Db::name('xorder_goods og')
->field("FLOOR(og.order_amount/100) price,count(og.id) count")
->join("xorder_infos oi","oi.order_id = og.order_id")
->where([["pay_status","=",1]])
->group('price')
->order('price','asc')
->select();
mysql
语句如下:SELECT FLOOR(og.order_amount/100) price,count(og.id) count
FROM tp5_xorder_goods og
INNER JOIN `tp5_xorder_infos` `oi` ON `oi`.`order_id`=`og`.`order_id`
WHERE `pay_status` = 1
GROUP BY `price`
ORDER BY `price` ASC
$titleArr = [];
//$res 为前面得到的数据
foreach ($res as $key => $value){
$price = $value['price'];
if ($price > 0){
$price_range = $price."00-".intval($price+1)."00(元)";
}else{
$price_range = "0-".intval($price+1)."00(元)";
}
$res[$key]['name'] = $price_range;
$res[$key]['value'] = $value['count'];
$titleArr[] = $price_range;
}
ECHARTS
图表展示,最终效果如下: