select
account.Name, account_history.parentId, account_history.State
from account
left join account_history on account_history.parentId = account.id
order by account.id desc
select count(*) from account_history where parentId in(select id from account) and Status = 'deleted'