现有用户表user_profile(device_id 设备号, gender 性别, age 年龄, university 学校, graduate_year 毕业年份, gpa 绩点, active_days_within_30 近30天活跃天数, question_cnt 发帖提问数, answer_cnt 答题数),示例数据如下: 题目练习表question_practice_detail(device_id 设备号, question_id 题目ID, result 答题结果),示例数据如下: 筛选出是北京大学或练题数大于2的学生ID,如果两个条件都满足,只输出一次。结果按设备号降序排序输出。示例数据输出如下:
示例1
输入
drop table if exists user_profile;
CREATE TABLE `user_profile` (
`id` int PRIMARY KEY AUTO_INCREMENT,
`device_id` int NOT NULL,
`gender` varchar(14) NOT NULL,
`age` int,
`university` varchar(32) NOT NULL,
`graduate_year` int,
`gpa` double,
`active_days_within_30` int ,
`question_cnt` int ,
`answer_cnt` int
);
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 user_profile(device_id, gender, age, university, graduate_year, gpa, active_days_within_30, question_cnt, answer_cnt) VALUES
(3214,'male',23,'北京大学',2022,3.7,15,5,25),
(2215,'male',23,'中国科学院大学',2023,3.6,5,1,2),
(6543,'female',22,'浙江大学',2024,3.9,12,3,30),
(2138,'male',21,'浙江大学',2024,3.8,7,2,12),
(2148,'male',22,'北京大学',2023,3.8,7,2,12),
(2315,'male',22,'复旦大学',2024,null,15,7,null);
INSERT INTO question_practice_detail(device_id,question_id,result) VALUES
(2138,111,'wrong'),
(3214,112,'wrong'),
(6543,111,'right'),
(6543,114,'right'),
(6543,116,'right'),
(2315,115,'right'),
(2315,116,'right'),
(2315,117,'wrong');
输出
device_id
6543
3214
2315
2148
加载中...