现有用户表user_profile(device_id 设备号, gender 性别, age 年龄, university 学校, graduate_year 毕业年份, gpa 绩点, active_days_within_30 近30天活跃天数, question_cnt 发帖提问数, answer_cnt 答题数),示例数据如下: 输出每个用户的第一有效关键信息,假设关键信息包括答题数、gpa、年龄,而这三个字段都可能为空。若答题数不为空返回答题数(如"答题数:3"),若答题数为空时返回gpa(如"gpa:3.6"),若gpa也为空返回年龄(如"年龄:23"),若年龄仍为空直接返回"暂无其他信息"。结果按设备号升序排序。示例数据输出如下:
示例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 
);

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.9,15,5,25),
	(2215,'male',23,'中国科学院大学',2023,3.8,5,1,2),
	(6543,'female',22,'北京大学',2024,3.7,12,3,30),
	(2138,'male',21,'浙江大学',2024,3.8,7,2,12),
	(2315,'male',22,'复旦大学',2024,null,15,7,null);

输出

device_id|key_info
2138|答题数:12
2215|答题数:2
2315|年龄:22
3214|答题数:25
6543|答题数:30
加载中...