select sum(count) as fcustcount from ( select ROW_NUMBER() over(partition by t1.channelid order by t1.time desc)as num, t1.count from tlive_usercount t1 inner join tlive t2 on t1.channelid = t2.channelid --and t2.livestatus='live' ) t where t.num = 1