牛客97114380...:select u.university,q.difficult_level,round(count(qd.question_id) / count(distinct qd.device_id), 4)'avg_answer_cnt' from user_profile u left join question_practice_detail qd on qd.device_id = u.device_id left join question_detail q on q.question_id = qd.question_id group by u.university,q.difficult_level having avg_answer_cnt > 0
0 点赞 评论 收藏
分享
已注销:题主用了inner join 就不用再考虑没有答题的同学了,内连接的特性就是两个表都有的才显示,如果根据两个表中的device_id进行连接的话,第一个表中没打过题的同学的device_id就不会再显示了
0 点赞 评论 收藏
分享
牛客78176060...:create or replace view V1 as select university,device_id from user_profile where university='浙江大学'; select q.device_id,question_id,result from question_practice_detail q inner join v1 on v1.device_id=q.device_id;
0 点赞 评论 收藏
分享
山有木兮木有枝.:order by 后面可以使用avg_question_cnt是不是因为select的执行顺序在order by之前?
0 点赞 评论 收藏
分享
yeahthon:正确的写法:select university, avg(question_cnt) as avg_question_cnt, avg(answer_cnt) as avg_answer_cnt from user_profile group by university having avg(question_cnt) < 5 or avg(answer_cnt) < 20; SQL的执行顺序,from、where、group by、having、select,在having中不应使用别名,因为别名的创建是在select中,而having在select之前执行,此时还没有别名
0 点赞 评论 收藏
分享
请求转运的弟弟:两个平均值不用保留一位小数吗?是不是加上round()更好?
0 点赞 评论 收藏
分享
牛牛学SQL:还需要加一个round函数,保留1位小数点。这个题目之所以不用round也能正确是因为gpa值本身就是1位小数点,但如果遇到多位小数的,就需要添加round函数才符合题意。
0 点赞 评论 收藏
分享
牛客41052077...:这道题为什么不用对age_cut进行分组呢,上一道题进行了分组
0 点赞 评论 收藏
分享
牛客86647388...:where month(date)=8 and year(date)=2021 换成 where left(date,7)='2021-08' 也可以
0 点赞 评论 收藏
分享
我见烈焰:请问一下,select count(date1)/count(date0) as avg_ret from ( select distinct date(t.date) as date0, t.device_id, t1.date as date1 from question_practice_detail as t left join question_practice_detail as t1 on t1.device_id=t.device_id and datediff(date(t1.date),date(t.date))=1 order by date0 ) as a 这样的作法提交也是正确的,但是否只是巧合有漏洞?
0 点赞 评论 收藏
分享
一帘风絮_:什么是前什么是后,建议使用左右来描述不容易有误解
0 点赞 评论 收藏
分享
Offer总会在不经...:请问为什么不用对年龄排序呢?我的答案错误了
0 点赞 评论 收藏
分享
0 点赞 评论 收藏
分享
牛客14952224...:row_number() over (partition by university order by gpa)改为rank() over (partition by university order by gpa) 更严谨一些
0 点赞 评论 收藏
分享
2525222:as did_cnt是什么意思呢
0 点赞 评论 收藏
分享
创作者周榜
更多
关注他的用户也关注了: