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 ('165','166','108','186','284','109','110','113','114','115','187','188','174','189','175','119','120','121','122','191','210','192','138','176','193','212','213','285','131','132','133','134','135','177','194','214','215','216','217','218','195','178','196','179','197','170','180','198','181','199','219','200','220','280','221','201','222','202','171','140','152','153','154','155','156','183','207','173','184','208','185','209') OR g.goods_id IN ('8636','8656','8677','8683','8684','8685','8686','8784','8796','8855','8857','8869','8870','8878','8879','8881','8888','8889','8892','8935') ) AND g.supplier_id=0 AND g.brand_id=3 ORDER BY salenum DESC LIMIT 200, 20 |