首页 > 试题广场 >

计算用户8月每天的练题数量

[编程题]计算用户8月每天的练题数量
  • 热度指数:311694 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 256M,其他语言512M
  • 算法知识视频讲解
题目:现在运营想要计算出2021年8月每天用户练习题目的数量,请取出相应数据。

示例:question_practice_detail
id device_id question_id result date
1 2138 111 wrong 2021-05-03
2 3214 112 wrong 2021-05-09
3 3214 113 wrong 2021-06-15
4 6543 111 right 2021-08-13
5 2315 115 right 2021-08-13
6 2315 116 right 2021-08-14
7 2315 117 wrong 2021-08-15
8 3214 112 wrong 2021-05-09
9 3214 113 wrong 2021-08-15
10 6543 111 right 2021-08-13
11 2315 115 right 2021-08-13
12 2315 116 right 2021-08-14
13 2315 117 wrong 2021-08-15
14 3214 112 wrong 2021-08-16
15 3214 113 wrong 2021-08-18
16 6543 111 right 2021-08-13


根据示例,你的查询应返回以下结果:
day question_cnt
13 5
14 2
15 3
16 1
18 1

示例1

输入

drop table if  exists `question_practice_detail`;
CREATE TABLE `question_practice_detail` (
`id` int NOT NULL,
`device_id` int NOT NULL,
`question_id`int NOT NULL,
`result` varchar(32) NOT NULL,
`date` date NOT NULL
);
INSERT INTO question_practice_detail VALUES(1,2138,111,'wrong','2021-05-03');
INSERT INTO question_practice_detail VALUES(2,3214,112,'wrong','2021-05-09');
INSERT INTO question_practice_detail VALUES(3,3214,113,'wrong','2021-06-15');
INSERT INTO question_practice_detail VALUES(4,6543,111,'right','2021-08-13');
INSERT INTO question_practice_detail VALUES(5,2315,115,'right','2021-08-13');
INSERT INTO question_practice_detail VALUES(6,2315,116,'right','2021-08-14');
INSERT INTO question_practice_detail VALUES(7,2315,117,'wrong','2021-08-15');
INSERT INTO question_practice_detail VALUES(8,3214,112,'wrong','2021-05-09');
INSERT INTO question_practice_detail VALUES(9,3214,113,'wrong','2021-08-15');
INSERT INTO question_practice_detail VALUES(10,6543,111,'right','2021-08-13');
INSERT INTO question_practice_detail VALUES(11,2315,115,'right','2021-08-13');
INSERT INTO question_practice_detail VALUES(12,2315,116,'right','2021-08-14');
INSERT INTO question_practice_detail VALUES(13,2315,117,'wrong','2021-08-15');
INSERT INTO question_practice_detail VALUES(14,3214,112,'wrong','2021-08-16');
INSERT INTO question_practice_detail VALUES(15,3214,113,'wrong','2021-08-18');
INSERT INTO question_practice_detail VALUES(16,6543,111,'right','2021-08-13');

输出

day|question_cnt
13|5
14|2
15|3
16|1
18|1
头像 webary
发表于 2021-09-03 13:54:08
精华题解 题意明确: 2021年8月每天用户练习题目的数量 问题分解: 限定条件:2021年8月,写法有很多种,比如用year/month函数的year(date)=2021 and month(date)=8,比如用date_format函数的date_format(date, "%Y-%m& 展开全文
头像 牛客题解官
发表于 2025-02-14 11:25:28
精华题解 题目描述 运营团队希望计算出 2021年8月 每天用户练习题目的数量。需从 question_practice_detail 表中提取相关数据,并按照日期统计每天的题目数量。 解题思路 我们需要从 question_practice_detail 表中筛选出 2021年8月 的数据。 提取日 展开全文
头像 不会打妖妖灵
发表于 2021-10-21 10:41:11
我个人觉得遇到这种模糊查询,like 关键字特别好用,下面是使用 like 关键字查询的题解: SELECT DAY(date) day, COUNT(question_id) question_cnt FROM question_practice_detail WHERE date like '% 展开全文
头像 DraonAbyss
发表于 2021-09-28 23:26:39
知识 日期函数 DAYOFWEEK(date) 返回日期date的星期索引(1=星期天,2=星期一, ……7=星期六)。这些索引值对应于ODBC标准。 select DAYOFWEEK('1998-02-03') -> 3 WEEKDAY(date) 返回date的星期索引(0=星期一,1=星 展开全文
头像 天天向好
发表于 2022-01-31 10:22:58
题目:【2021】年【8】月每天用户练习【题目数量】。 分析:时间条件可用date between 2021-08-01 and 2021-08-31 或者 year(date)=2021 and month(date)=8;题目数量使用count函数;截取日期函数用extract(day f 展开全文
头像 2157
发表于 2021-12-22 14:23:24
mysql 日期时间常用函数: 1.获取系统时间 #获取当前系统的日期时间 SELECT NOW(); # 2021-12-22 13:50:58 #获取当前系统的日期 SELECT CURDATE(); # 2021 展开全文
头像 牛客182179768号
发表于 2021-09-23 11:31:04
主要考察日期函数的使用思路:第一,每天练题数量的统计,要查询出每天,利用DAY(date) 实现并重名为day,再进行GROUP BY的分组;第二,WHERE条件筛选出YEAR(date)="2021" and month(date)="08" 的“21年8月 展开全文
头像 牛客78575463号
发表于 2021-10-21 10:57:12
1、day函数 定义: DAY函数返回指定日期的日的部分 语法: DAY(date) 参数: ①date参数是合法的日期表达式。 返回值: int型数据 2、substr函数格式 (俗称:字符截取函数)   格式1: substr(string string, int a, int b);    展开全文
头像 牛客987852806号
发表于 2021-08-30 17:44:18
selectDATE_FORMAT(date,'%e') as day,count(question_id)from question_practice_detailWHEREDATE_FORMAT(date,'%Y-%m')='2021-08'group by day DATE_FORMAT(d 展开全文
头像 学到猝死就行了
发表于 2022-04-05 10:39:37
select day(date) day, count(question_id) question_cnt from question_practice_detail group by date having date like "2021-08-%" 感觉用这个having 模糊查询就行了呀 代 展开全文
头像 刘大漂亮lmq
发表于 2021-11-09 15:55:43
知识点:group by substr count select SUBSTR(date,9,10) as day, count(question_id) as question_cnt from question_practice_detail where SUBSTR(date,1,7) 展开全文
头像 潘婷婷-123
发表于 2023-02-15 23:53:38
select day,count(question_id) as question_cnt from -- 创建子查询 ( select *, month(date) as month, day(date) as day from question_practice_detail ) a 展开全文