现有题目练习表question_practice_detail(device_id 设备号, question_id 题目ID, result 答题结果, event_date 日期),示例数据如下: 请统计用户每月最后一周的练题数,每月最后一周指该月的最后7天,结果按设备号和月份升序排序。示例数据输出如下:
示例1
输入
drop table if exists `question_practice_detail`;
CREATE TABLE `question_practice_detail` (
`id` int PRIMARY KEY AUTO_INCREMENT,
`device_id` int NOT NULL,
`question_id`int NOT NULL,
`result` varchar(32) NOT NULL,
`event_date` date
);
INSERT INTO question_practice_detail(device_id,question_id,result,event_date) VALUES
(2138,111,'wrong','2021-07-03'),
(3214,112,'wrong','2021-08-28'),
(3214,112,'wrong','2021-08-09'),
(3214,113,'wrong','2021-08-15'),
(3214,112,'wrong','2021-08-29'),
(6543,111,'right','2021-08-26'),
(3217,114,'wrong','2021-07-21');
输出
device_id|ym|cnt
3214|2021年08月|2
6543|2021年08月|1
加载中...