SELECT di.customer_code ,di.create_date ,di.create_time ,cu.customer_name1 ,cu.customer_name2 ,sd.download_date ,di.invoice_id FROM invoice_search_index di LEFT OUTER JOIN customer cu ON di.customer_code = cu.customer_code LEFT OUTER JOIN ( SELECT invoice_id ,create_time ,MIN(download_date) as download_date FROM download_history_invoice WHERE admin_id = 0 GROUP BY invoice_id, create_time) sd ON di.invoice_id = sd.invoice_id AND di.create_time = sd.create_time WHERE di.customer_code <> '' AND di.create_date >= '2025-06-25' ORDER BY di.create_time DESC, di.customer_code LIMIT 1001