当前位置: 首页 > news >正文

牛客网SQL进阶129 :月均完成试卷数不小于3的用户

月均完成试卷数不小于3的用户爱作答的类别_牛客题霸_牛客网

0 问题描述

  基于试卷作答记录表exam_record、试卷信息表examination_info ,统计出 “月均完成试卷数”不小于3的用户作答的类别及作答次数,按次数降序输出。

1 数据准备

drop table if exists examination_info;
CREATE TABLE examination_info (id int PRIMARY KEY AUTO_INCREMENT COMMENT '自增ID',exam_id int UNIQUE NOT NULL COMMENT '试卷ID',tag varchar(32) COMMENT '类别标签',difficulty varchar(8) COMMENT '难度',duration int NOT NULL COMMENT '时长',release_time datetime COMMENT '发布时间'
)CHARACTER SET utf8 COLLATE utf8_general_ci;drop table if exists exam_record;
CREATE TABLE  exam_record (id int PRIMARY KEY AUTO_INCREMENT COMMENT '自增ID',uid int NOT NULL COMMENT '用户ID',exam_id int NOT NULL COMMENT '试卷ID',start_time datetime NOT NULL COMMENT '开始时间',submit_time datetime COMMENT '提交时间',score tinyint COMMENT '得分'
)CHARACTER SET utf8 COLLATE utf8_general_ci;INSERT INTO examination_info(exam_id,tag,difficulty,duration,release_time) VALUES(9001, 'SQL', 'hard', 60, '2020-01-01 10:00:00'),(9002, 'SQL', 'easy', 60, '2020-02-01 10:00:00'),(9003, '算法', 'medium', 80, '2020-08-02 10:00:00');INSERT INTO exam_record(uid,exam_id,start_time,submit_time,score) VALUES
(1001, 9001, '2021-07-02 09:01:01', '2021-07-02 09:21:01', 80),
(1002, 9001, '2021-09-05 19:01:01', '2021-09-05 19:40:01', 81),
(1002, 9002, '2021-09-02 12:01:01', null, null),
(1002, 9003, '2021-09-01 12:01:01', null, null),
(1002, 9001, '2021-07-02 19:01:01', '2021-07-02 19:30:01', 82),
(1002, 9002, '2021-07-05 18:01:01', '2021-07-05 18:59:02', 90),
(1003, 9002, '2021-07-06 12:01:01', null, null),
(1003, 9003, '2021-09-07 10:01:01', '2021-09-07 10:31:01', 86),
(1004, 9003, '2021-09-06 12:01:01', null, null),
(1002, 9003, '2021-09-01 12:01:01', '2021-09-01 12:31:01', 81),
(1005, 9001, '2021-09-01 12:01:01', '2021-09-01 12:31:01', 88),
(1005, 9002, '2021-09-01 12:01:01', '2021-09-01 12:31:01', 88),
(1006, 9002, '2021-09-02 12:11:01', '2021-09-02 12:31:01', 89);

2 数据分析

-- MySQL写法
selectb.tag,count(*) cnt
from exam_record a
left join examination_info bon a.exam_id = b.exam_id
wherea.uid in (selectuidfrom exam_recordwhere submit_time is not nullgroup byuid,date_format(submit_time, "%Y%m")havingcount(submit_time) > 2)
group by b.tag
order by cnt desc;

思路分析:

  • step1: 先筛选出 月均完成试卷数不小于3的用户;
  • step2:按examination_info表的tag进行分组统计,最后降序输出;

3 小结

http://www.lryc.cn/news/427456.html

相关文章:

  • Astro + Cloudflare Pages 快速搭建个人博客
  • Vue中<style scoped>与<style module>的深入解析与应用
  • Qt系列之数据库(二)代码篇
  • @RequstParam@PathVariable@RequestBody的区别
  • Maven继承和聚合特性
  • python opencv实时视频输入
  • 为什么头文件不能写using namespace
  • 使用 preloadRouteComponents 提升 Nuxt 应用的性能
  • mybatisPlus的@TableLogic逻辑删除注解导致联合索引失效的坑
  • C# 隐式转换和显式转换
  • 入门网络安全工程师要学习哪些内容
  • 深入理解 Go 并发原语
  • 计算机毕业设计选题推荐-springboot 基于springboot的宠物健康顾问系统
  • 数据结构—— 初识二叉树
  • 2024.08.09校招 实习 内推 面经
  • IDEA中设置类和方法的注释
  • Adobe Premiere Pro 2023-23.6.7.1 解锁版下载与安装教程 (一款专业的视频编辑软件)
  • openGauss 6.0安装过程解除对root用户依赖之gs_preinstall
  • IOS 10 统一颜色管理和适配深色模式
  • Linux目录结构及基础查看命令和命令模式
  • UDP和TCP协议段格式分析
  • Go语言基础--条件判断(if语句)
  • 白骑士的C#教学实战项目篇 4.2 图形用户界面(GUI)应用
  • 【Java学习】反射和枚举详解
  • leetcode-461. 汉明距离
  • rpmbuild 将二进制文件 strip,文件 md5 发生改变
  • selenium爬取搜狗网站新闻的小Demo
  • R 语言学习教程,从入门到精通,R CSV 文件使用(17)
  • 【LLM之Base Model】Weaver论文阅读笔记
  • 泰坦尼克号 - 从灾难中学习机器学习/Titanic - Machine Learning from Disaster(kaggle竞赛)第一集(了解赛题)