select p.*, if(wpm.pm_code IS NULL, p.code, wpm.pm_code) AS mcode, if(wpm.pm_name IS NULL, p.name, wpm.pm_name) AS mname,
if(wpm.sell_prc > 0, wpm.sell_prc, min(p.sell_prc)) AS msell_prc, if(wpm.normal_prc > 0, wpm.normal_prc, min(p.normal_prc)) AS mnormal_prc,
if(wpm.`status` > 0, wpm.`status`, MIN(p.stat)) AS mstatus from wm_product p left JOIN wm_product_master_mapping wpmm ON wpmm.p_no = p.no left JOIN wm_product_master wpm ON wpm.no = wpmm.pm_no where 1 and stat in (2,3) and !(stat = 3 and hide_soldout_yn = 'Y') and `big`=1001 and perm_lst='Y' and p.stat IN (2,3) and (prd_gubun in ('C','N') /*or (prd_gubun='P' and cm_no=0)*/) group by mcode order by stat, `hit_view` desc, p.sortbig desc, p.no desc