SQL VQ13 统计每天总刷题数
SQL VQ13 统计每天总刷题数
- 数据
- 需求
- 解决
题目 : https://www.nowcoder.com/practice/4856eb2785544c029da140ee0f60c0ba?tpId=341
数据
drop table if exists questions_pass_record_detail;
CREATE TABLE `questions_pass_record_detail` (
`user_id` int NOT NULL,
`question_type` varchar(32) NOT NULL,
`device` varchar(14) NOT NULL,
`pass_count` int NOT NULL,
`date` date NOT NULL
);
INSERT INTO questions_pass_record_detail VALUES(101, 'java', 'app', 2, '2020-03-01');
INSERT INTO questions_pass_record_detail VALUES(102, 'sql', 'pc', 15,'2021-07-07');
INSERT INTO questions_pass_record_detail VALUES(102, 'python', 'pc', 9, '2021-04-09');
INSERT INTO questions_pass_record_detail VALUES(104, 'python', 'app', 3,'2022-03-17');
INSERT INTO questions_pass_record_detail VALUES(105, 'sql', 'pc', 60, '2016-08-15');
INSERT INTO questions_pass_record_detail VALUES(204, 'sql', 'pc', 20, '2019-05-15');
需求
统计每天 days 总刷题数 passCnt
查询结果 :
days|passCnt
2020-03-01|2
2021-07-07|15
2021-04-09|9
解决
思路 :
- 每天 days , 就是对每天进行分组
- 并在每天中求刷题数的总和
select `date` as days,
sum(pass_count) as passCnt
from questions_pass_record_detail
group by `date`;