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 (replace(replace(`name`, '\\', ''), ' ', '') like '%[부산]%' or replace(replace(`keyword`, '\\', ''), ' ', '') like '%[부산]%' or `code` like '%[부산]%' or `name_eng` like '%[부산]%' ) and wm_sc='0' and perm_sch='Y' and p.stat IN (2,3) and `wm_sc`=0 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