i think the query should be something like
DELETE FROM
ledger l
JOIN Party ON p.Id = l.Account_Id
JOIN Party ON p.Id = l.ContraAccount_Id
LEFT JOIN AcGroup acg ON acg.Id = p.AcGroup_Id
WHERE acg.Id is NULL
Before deleting the contents check the data by using the Select statement. If the records are correct then execute the delete statement..