SQL8. 查找某个年龄段的用户信息
描述
id | device_id | gender | age | university | province |
1 | 2138 | male | 21 | 北京大学 | Beijing |
2 | 3214 | male | | 复旦大学 | Shanghai |
3 | 6543 | female | 20 | 北京大学 | Beijing |
4 | 2315 | female | 23 | 浙江大学 | ZheJiang |
5 | 5432 | male | 25 | 山东大学 | Shandong |
device_id | gender | age |
2138 | male | 21 |
6543 | female | 20 |
2315 | female | 23 |
示例1
输入:
drop table if exists user_profile; 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, `province` varchar(32) NOT NULL); INSERT INTO user_profile VALUES(1,2138,'male',21,'北京大学','BeiJing'); INSERT INTO user_profile VALUES(2,3214,'male',null,'复旦大学','Shanghai'); INSERT INTO user_profile VALUES(3,6543,'female',20,'北京大学','BeiJing'); INSERT INTO user_profile VALUES(4,2315,'female',23,'浙江大学','ZheJiang'); INSERT INTO user_profile VALUES(5,5432,'male',25,'山东大学','Shandong');
输出:
2138|male|21 6543|female|20 2315|female|23
Mysql 解法, 执行用时: 36ms, 内存消耗: 6388KB, 提交时间: 2022-01-01
select device_id,gender,age from user_profile where age between 20 and 23;
Mysql 解法, 执行用时: 36ms, 内存消耗: 6388KB, 提交时间: 2021-12-31
SELECT device_id,gender ,age from user_profile where age BETWEEN 20 and 23;
Mysql 解法, 执行用时: 36ms, 内存消耗: 6396KB, 提交时间: 2022-01-26
select device_id,gender,age from user_profile where (age >= 20 and age <= 23)
Mysql 解法, 执行用时: 36ms, 内存消耗: 6404KB, 提交时间: 2022-01-01
select device_id, gender, age from user_profile where age >= 20 and age <=23;
Mysql 解法, 执行用时: 36ms, 内存消耗: 6428KB, 提交时间: 2022-01-22
select device_id,gender,age FROM user_profile where age between 20 and 23