public static function getProductBusinessStoreListCountBymap($where, $pageSize, $pageIndex = 1)
{
//$list = Db::query("SELECT p.* FROM ( SELECT * FROM ims_tp_product ORDER BY saleAmount DESC) AS p GROUP BY p.business_id ORDER BY p.saleAmount desc");
/*销量排行*/
$city_id = $where['city_id'];
$classify_id = $where['classify_id'];
$page = ($pageIndex - 1) * $pageSize;
$list = Db::query(
"SELECT b.*,n.id as pid,n.saleAmount FROM ims_tp_business as b INNER JOIN (SELECT p.* FROM
( SELECT * FROM ims_tp_product ORDER BY saleAmount DESC )
AS p GROUP BY p.business_id ORDER BY p.saleAmount DESC)
as n ON n.business_id = b.id WHERE n.status = 1 and b.status = 1 and b.classify_id = $classify_id
and b.city_id = $city_id ORDER BY n.saleAmount DESC limit $page,$pageSize"
);
return $list;
}
在项目中常常需要根据产品销量由高到低排列店铺,这里用到数据库子查询,还是蛮好用的
ims_tp_business为店铺表,ims_tp_product为产品表