select t1.room_id,t1.room_name,count(distinct case when hour(in_time)=23 or hour(out_time)=23 then user_id end) as user_count from room_info_tb t1 left join user_view_tb t2 on t1.room_id=t2.room_id group by room_id,room_name order by user_count desc ;