题解 | #21年8月份练题总数#
21年8月份练题总数
https://www.nowcoder.com/practice/b8f30b239b454ed490367b53ea95607d
发现更牛的写法,就是用group by去代替distinct,因为在数据量大的情况下,去重会消耗性能。
select count(temp.did_cnt) as did_cnt, sum(temp.q_cnt) as question_cnt from( select count(1) as did_cnt, count(question_id) as q_cnt from question_practice_detail where date >= '2021-08-01' and date <= '2021-08-31' group by device_id ) temp