select count(distinct device_id) as did_cnt,
       count(question_id)        as question_cnt
from (
         select up.device_id,
                question_id,
                date
         from user_profile up
                  join question_practice_detail qpd on up.device_id = qpd.device_id
         where month(date) = 8
           and year(date) = 2021
     ) as t