首页 > 试题广场 >

21年8月份练题总数

[编程题]21年8月份练题总数
  • 热度指数:160758 时间限制: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
……




根据的示例,你的查询应返回以下结果:
did_cnt question_cnt
3 12
示例1

输入

drop table if exists `user_profile`;
drop table if  exists `question_practice_detail`;
CREATE TABLE `user_profile` (
`id` int NOT NULL,
`device_id` int NOT NULL,
`gender` varchar(14) NOT NULL,
`age` int ,
`university` varchar(32) NOT NULL,
`gpa` float,
`active_days_within_30` int ,
`question_cnt` int ,
`answer_cnt` int 
);
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 user_profile VALUES(1,2138,'male',21,'北京大学',3.4,7,2,12);
INSERT INTO user_profile VALUES(2,3214,'male',null,'复旦大学',4.0,15,5,25);
INSERT INTO user_profile VALUES(3,6543,'female',20,'北京大学',3.2,12,3,30);
INSERT INTO user_profile VALUES(4,2315,'female',23,'浙江大学',3.6,5,1,2);
INSERT INTO user_profile VALUES(5,5432,'male',25,'山东大学',3.8,20,15,70);
INSERT INTO user_profile VALUES(6,2131,'male',28,'山东大学',3.3,15,7,13);
INSERT INTO user_profile VALUES(7,4321,'male',28,'复旦大学',3.6,9,6,52);
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');

输出

3|12
select count(DISTINCT(device_id)) as did_cnt,
count(device_id) as question_cnt
from question_practice_detail
where date like "2021-08-%";

发表于 2024-04-27 20:04:29 回复(0)
select
    count(t1.device_id),
    sum(t1.did_cnt)
from
    (
        select
            device_id,
            count(device_id) as did_cnt
        from
            question_practice_detail
        where
            month (date) = 08
            and year (date) = 2021
        group by
            device_id
    ) t1

发表于 2024-03-02 20:22:52 回复(0)
select count(distinct device_id) as did_cnt,
count(question_id) as question_cnt
from question_practice_detail
where extract(month from date) = 8 
and extract(year from date) = 2021;
发表于 2024-02-17 17:08:41 回复(0)
select 
count(distinct device_id) did_cnt,
count(id) question_cnt 
from question_practice_detail 
where date like '2021-08%';

发表于 2024-02-04 23:50:54 回复(0)
select count(distinct device_id),count(device_id)
from question_practice_detail 
where date like '2021-08%';

发表于 2023-12-06 11:53:06 回复(0)
select count(distinct(device_id)) as did_cnt ,count(device_id) as question_cnt  
from question_practice_detail
where date like "2021-08%"
#where year(date)='2021' and month(date)='08'
#需要看清题目,总是筛错数据
#%:表示任意个或多个字符。可匹配任意类型和长度的字符。另外,如果需要找出表中”既有 又有“的记录,请使用and条件
#_:表示任意单个字符。匹配单个任意字符,它常用来限制表达式的字符长度语句:(可以代表一个中文字符)
#如果我就真的要查%或者_,使用escape,转义字符/后面的%或_就不作为通配符了,注意前面没有转义字符的%和_仍然起通配符作用
发表于 2023-08-24 09:45:40 回复(0)
select
count(distinct device_id) as did_cnt,
count(question_id) as question_cnt
from
question_practice_detail
where
month(date) = '08'

发表于 2023-08-18 12:04:16 回复(0)
SELECT
    COUNT(DISTINCT device_id) AS did_cnt,
    COUNT(question_id) AS question_cnt
FROM question_practice_detail
WHERE date LIKE('2021-08-%')
;
发表于 2023-08-01 15:55:02 回复(0)
select
    count(distinct device_id) did_cnt,
    count(question_id) question_cnt
    from
    question_practice_detail
    where month(date)='08' and result is not null;

发表于 2023-07-17 19:14:56 回复(0)
SELECT COUNT(DISTINCT device_id) AS did_cnt,COUNT(question_id) AS question_cnt
FROM question_practice_detail
WHERE `date` LIKE "2021-08_%";
发表于 2023-07-14 10:17:42 回复(0)
select
    count(distinct device_id) as did_cnt,
    count(id) as question_cnt
from
    question_practice_detail
where
    month (date) = '8'
    and year (date) = '2021'
    # date_format(date,'%y%m') = '2108'
    # date like '2021-08%'
    # mid(date,1,7) = '2021-08'
    # date_format(date,'%Y%m') = '202108'
    # substring(date,1,7) = '2021-08'
    # left(date,7) = '2021-08'
    # substring_index(date,'-',2) = '2021-08'

发表于 2023-06-21 00:29:58 回复(0)
select
   count(distinct device_id) as did_cnt,
   count(question_id) as question_cnt
from
    question_practice_detail
where
    year (date) = 2021
    and month (date) = 8

发表于 2023-06-17 15:30:40 回复(0)
1.先根据用户分组求出每个用户的答题次数
        select
            count(question_id) count_all
        from
            question_practice_detail
        where
            month (date) = 8
        group by
            device_id

2.然后统计用户的个数和统计总的答题个数
select
    count(1) did_cnt,
    sum(count_all) question_cnt
from
    (
        select
            count(question_id) count_all
        from
            question_practice_detail
        where
            month (date) = 8
        group by
            device_id
    ) t1;


发表于 2023-06-13 14:20:28 回复(0)
select count(distinct device_id) did_cnt,count(question_id) question_cnt from question_practice_detail where date like "2021-08-%";
发表于 2023-05-08 22:06:17 回复(0)
SELECT
    COUNT(DISTINCT device_id) AS did_cnt,
    COUNT(question_id) AS question_cnt
FROM
    question_practice_detail
WHERE
    date BETWEEN '2021-08-01' AND '2021-08-31'

发表于 2023-04-11 16:34:30 回复(0)
select
    count(distinct (device_id)) as did_cnt,
    count(question_id) as question_cnt
from
    question_practice_detail
where
    date regexp "2021-08"


正则表达式也可以哦
发表于 2023-04-10 16:58:09 回复(0)
select
   count(distinct device_id) did_cnt,
   count(question_id) question_cnt
from question_practice_detail
where left(date,7)='2021-08'
发表于 2023-03-30 14:39:51 回复(0)
select 
 count(distinct(device_id)) as did_cut,
 count(id) as question_cnt
from 
 question_practice_detail
where 
 year(date) = 2021 and month(date) = 08;

发表于 2023-03-22 20:22:11 回复(0)
select count(  distinct  device_id)as did_cnt
,count(result) as question_cnt
from question_practice_detail
where substr(replace(date,'-',''),1,6)='202108'



发表于 2023-02-22 16:21:27 回复(0)

问题信息

难度:
185条回答 2028浏览

热门推荐

通过挑战的用户

查看代码