写了两种方法,我想知道在实际工作中那种效率更高?求大牛讲解一下,谢谢啦!!
#方法一:
SELECT
university
,ROUND(COUNT(q.result)/COUNT(DISTINCT q.device_id),4) avg_answer_cnt
FROM
user_profile u
JOIN
question_practice_detail q
WHERE
u.device_id = q.device_id
GROUP BY
university;
#方法二:答案是一样的,只是牛客网的评改系统过不了
SELECT
t1.un university
,ROUND(SUM(c_re)/COUNT(t1.de_id),4) avg_answer_cnt
FROM(
SELECT
university un
,q.device_id de_id
,COUNT(result) c_re
FROM
user_profile u
JOIN
question_practice_detail q
WHERE
u.device_id = q.device_id
GROUP BY
university
,q.device_id
) AS t1
GROUP BY
t1.un

京公网安备 11010502036488号