=====sql1===== SELECT mp_player_id AS mp_pl_id ,mp_sts,mp_notes,mp_class ,su_score,su_to_par,su_rank ,su_rank_code,su_sts ,su_new_total ,su_hdcp,su_net,case when su_net=0 then 1000.0 else su_net end as su_net123 ,CASE WHEN su_rank is null OR su_rank=0 THEN 0 ELSE 1 END AS is_null ,gm.`name` ,gm.id ,(SELECT count(1) FROM player_score WHERE sc_pl_id=su_pl_id and sc_mt_id='8900' and sc_rd_id='3' ) as completedholes FROM match_player LEFT JOIN player_summary ON mp_player_id = su_pl_id AND mp_match = su_mt_id AND su_rd_id = '3' LEFT JOIN gp_manage gm ON gm.id = mp_class WHERE mp_match = '8900' AND mp_notes not in ('R1','R2','R3') ORDER BY mp_class ASC,is_null DESC, su_rank ,completedholes desc ,su_pl_id =====sql2===== SELECT mp_player_id AS mp_pl_id, mp_sts, mp_notes, su_score, su_to_par, su_rank, su_rank_code, su_sts,su_new_total,su_hdcp,su_net FROM match_player LEFT JOIN player_summary ON mp_player_id = su_pl_id AND mp_match = su_mt_id AND su_rd_id = '3' WHERE mp_match = '8900' and mp_sts<>'' AND mp_notes = 'R3' ORDER BY mp_sts,su_rank , su_pl_id