SELECT IF(d030xref.Data_MB IN (0, 999999), 0, IFNULL(( SELECT ROUND(SUM(ctn_iv_used_prd_1), 2) FROM SWWITS_usage_tm c WHERE c.BAN = db2.Acct_BAN AND c.SUBSCRIBER_NO = db2.Subs_CTN AND c.record_type IN (1, 2, 3, 4, 5, 6) AND c.delete_flag = 0 ), 0) / d030xref.Data_MB * 100) as 'c19' FROM BANFileDB2 db2 LEFT JOIN SWWITS_BAN_cmp_xref banxref ON ( banxref.BAN_numeric_id = db2.Acct_BAN AND banxref.company_id = db2.company_id ) LEFT JOIN SWWITS_dd_230_TM_consolidation d230 ON ( d230.dd_230_TM_consolidation_id = IF( db2.latest_dd_230_id > 0, db2.latest_dd_230_id, (SELECT max(ddtm.dd_230_TM_consolidation_id) FROM SWWITS_dd_230_TM_consolidation ddtm WHERE ddtm.company_id = db2.company_id AND ddtm.BAN = db2.Acct_BAN AND ddtm.PTN = db2.Subs_CTN AND (ddtm.Detail_month = DATE_FORMAT(CURRENT_TIMESTAMP(), '%Y-%c-01')) ) ) ) LEFT JOIN SWWITS_dd_030_plan_list_cmp_xref d030xref ON ( d030xref.dd_030_plan_list_cmp_xref_id = d230.dd_030_plan_list_xref_id ) LEFT JOIN SWWITS_ptn_DAC_UDI dacudi ON ( dacudi.company_id = db2.company_id AND dacudi.BAN_Account_Number = db2.Acct_BAN AND dacudi.ptn = db2.Subs_CTN ) WHERE 1=1 AND db2.company_id = 242 AND db2.Acct_BAN IN ('944633527') AND (banxref.end_of_BAN_usage IS NULL OR banxref.end_of_BAN_usage > CURRENT_TIMESTAMP()) AND DATE_ADD(d230.end_coverage_date, INTERVAL 1 MONTH) + INTERVAL 1 DAY > NOW() ORDER BY IF(d030xref.Data_MB IN (0, 999999), 0, IFNULL(( SELECT ROUND(SUM(ctn_iv_used_prd_1), 2) FROM SWWITS_usage_tm c WHERE c.BAN = db2.Acct_BAN AND c.SUBSCRIBER_NO = db2.Subs_CTN AND c.record_type IN (1, 2, 3, 4, 5, 6) AND c.delete_flag = 0 ) , 0) / d030xref.Data_MB * 100) DESC LIMIT 0, 10;