DELETE
FROM `portrait_tc_call_record`
WHERE
detailsId IN (
SELECT cr.detailsId
FROM ( SELECT detailsId
FROM `portrait_tc_call_record`
GROUP BY detailsId,party_id,bill_Month
HAVING COUNT(detailsId) > 1
) cr
)
AND id NOT IN (
SELECT tc.id
FROM ( SELECT MIN(id) id
FROM `portrait_tc_call_record`
GROUP BY detailsId,party_id,bill_Month
HAVING COUNT(detailsId) > 1
) tc
)