何健雄 2022-05-18 09:14 采纳率: 0%
浏览 159

mysql 查询用户连续3天答题分数等于100分的数据,

mysql 查询用户连续3天答题分数等于100分的数据,
DROP TABLE IF EXISTS t_exam;
CREATE TABLE t_exam (
id int(11) NOT NULL AUTO_INCREMENT,
user_id varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '用户ID',
fraction int(11) NULL DEFAULT NULL COMMENT '分数',
create_time datetime(0) NULL DEFAULT NULL COMMENT '创建时间',
PRIMARY KEY (id) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 7 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;

INSERT INTO t_exam VALUES (1, '001', 100, '2022-05-14 09:04:38');
INSERT INTO t_exam VALUES (2, '001', 100, '2022-05-15 09:05:04');
INSERT INTO t_exam VALUES (3, '001', 100, '2022-05-16 09:05:15');
INSERT INTO t_exam VALUES (4, '001', 90, '2022-05-17 09:05:40');
INSERT INTO t_exam VALUES (5, '002', 100, '2022-05-14 09:08:54');
INSERT INTO t_exam VALUES (6, '002', 100, '2022-05-15 09:09:05');

SET FOREIGN_KEY_CHECKS = 1;
感谢 各位的帮助
如果可以的话 希望能有sql 语句

  • 写回答

1条回答 默认 最新

  • 魂落忘川犹在川 2022-05-18 10:34
    关注
    select user_id,fraction  from (
    select user_id
    ,fraction 
    , the_date 
    , DATE_SUB(the_date,INTERVAL ROW_NUMBER() over(partition by user_id order by the_date ) day ) as res_date
    from 
      (
       select user_id,fraction, date(CREATE_time) as the_date from t_exam where fraction =100 group by user_id,fraction,date(CREATE_time)  
      ) a 
        ) b group by user_id,fraction having count(res_date) >= 3 
        
    
    评论 编辑记录

报告相同问题?

问题事件

  • 创建了问题 5月18日

悬赏问题

  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?