题解 | #统计复旦用户8月练题情况#
统计复旦用户8月练题情况
https://www.nowcoder.com/practice/53235096538a456b9220fce120c062b3
select up.device_id ,university ,count(question_id) as question_cnt ,sum(if(result = 'right',1,0)) as right_question_cnt from user_profile as up left join question_practice_detail as qpd on up.device_id = qpd.device_id where university = '复旦大学' and month(date) = 8 group by up.device_id
注意:一、算正确题目数:sum(if(result = 'right',1,0)) 为什么不用count,暂时不知道。
二、表链接注意要求的字段名要加表名,特别是两个表有重合的情况下,不然紧到出错,tmd。