select
ad.*,
ab.balance
from
(
select
account_id, max(date) as max_date
from tmp_account_balance
group by account_id
) ad
inner join tmp_account_balance ab on ad.account_id = ab.account_id and ab.date = ad.max_date;
select
ct.id,
count(1) as allnews_
from dle_category ct
left join dle_post ps on ps.id = ct.id
where true
and ps.approve = '1'
group by ct.id