SQL | SELECT IFNULL(o.num,0) AS salenum, g.goods_id, g.goods_name, g.click_count, g.goods_number, g.goods_name_style, g.market_price, g.is_new, g.is_best, g.is_hot, g.shop_price AS org_price, IFNULL(mp.user_price, g.shop_price * '1') AS shop_price, g.promote_price, g.goods_type, g.promote_start_date, g.promote_end_date, g.goods_brief, g.goods_thumb , g.goods_img FROM `hbyuc`.`shop_goods` AS g LEFT JOIN `hbyuc`.`shop_member_price` AS mp ON mp.goods_id = g.goods_id AND mp.user_rank = '0' LEFT JOIN (SELECT SUM(og.`goods_number`) AS num,og.goods_id FROM ecs_order_goods AS og, ecs_order_info AS oi WHERE oi.pay_status = 2 AND oi.order_status >= 1 AND oi.order_id = og.order_id GROUP BY og.goods_id) AS o ON o.goods_id = g.goods_id WHERE g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 AND (g.cat_id IN ('167','223','230','231','232','233','234','235','236','281','237','283','238','224','239','240','241','242','243','244','245','246','225','247','248','249','250','251','252','253','226','254','255','256','257','258','259','260','227','261','262','263','264','228','265','266','267','229','268','269','270') OR g.goods_id IN ('8699','8710','8798','8837','8839','8840','8933','8934') ) AND g.supplier_id>0 AND g.brand_id=1 ORDER BY salenum DESC LIMIT 20 |