SQL刷题 牛客23
SQL1
top 2 -->结尾处limit 2
SQL13
in('1','3','5') 找的内容不连续 between 1 and 5 包含首尾,找的内容连续 is/is not NULL
SQL18
select gender,university,count(device_id) user_num,round(avg(active_days_within_30),1) avg_active_day,round(avg(question_cnt),1) avg_question_cnt from user_profile group by gender,university //按照性别和学校分组
(round,保留小数)
相关用法: select * from table where 过滤条件 group by 分组条件 having 筛选特定分组 order by 排序
limit
SQL19
select university,avg(question_cnt) avg_question_cnt,avg(answer_cnt) avg_answer_cnt
from user_profile group by university
having avg_question_cnt<5 or avg_answer_cnt<20
SQL20
select university,avg(question_cnt) avg_question_cnt
from user_profile
group by university
order by avg_question_cnt
SQL22
//某学校用户平均答题数量计算方式:该学校用户答题总次数除以答过题的不同用户个数 select up.university,count(question_id)/count(distinct qp.device_id) avg_answer_cnt from user_profile as up,question_practice_detail as qp where qp.device_id=up.device_id group by up.university order by university select university,count(question_id)/count(distinct qp.device_id) avg_answer_cnt from question_practice_detail as qp inner join user_profile as up on qp.device_id=up.device_id group by university order by university
SQL23
//计算一些参加了答题的不同学校、不同难度的用户平均答题量 select university,difficult_level,count(qp.question_id)/count(distinct qp.device_id) avg_answer_cnt from user_profile as up,question_practice_detail as qp,question_detail as qd where qp.device_id=up.device_id and qp.question_id=qd.question_id group by university,difficult_level
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY