尝试使用子选择,首先对它们进行排序,然后对它们进行分组,正常的分组依据将使用记录的第一次出现,所以使它像第一个ORDER BY service_id DESC然后使用分组依据
SELECT t.* FROM (
select * from billing_billingmatrix
where (provider_id=24
or provider_id is null)
and (service_id=25 or service_id is null)
ORDER BY service_id DESC
) t GROUP BY t.definition_id