select T.user_id '姓名',count(*) '沙发数',group_concat(T.topic_id) 'topic_id'
from (
select *
from comments A
where not exists (select 1 from comments where A.rowdate<rowdate and A.topic_id=topic_id)
)T
group by T.user_id
select a.id,a.name,count(*),group_concat(b.topic_id) from user a inner join comments b on a.user_id=b.user_id
inner join topic c on c.id=b.topic_id
group by a.id,a.name