数据库基础数据:
表名:user_profile
| 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 |
建表语句:
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');
题目:现在运营想要查看用户信息表中所有的数据,请你取出相应结果
select
*
from
user_profile;
题目:现在运营同学想要用户的设备id对应的性别、年龄和学校的数据,请你取出相应数据
select
device_id,
gender,
age,
university
from
user_profile;
题目:现在运营需要查看用户来自于哪些学校,请从用户信息表中取出学校的去重数据。
select
distinct university
from
user_profile;
题目:现在运营只需要查看前2个用户明细设备ID数据,请你从用户信息表 user_profile 中取出相应结果。
select
device_id
from
user_profile
limit
2;
题目:现在你需要查看前2个用户明细设备ID数据,并将列名改为 ‘user_infos_example’,,请你从用户信息表取出相应结果。
select
device_id as user_infos_example
from
user_profile
limit
2;
题目:现在运营想要筛选出所有北京大学的学生进行用户调研,请你从用户信息表中取出满足条件的数据,结果返回设备id和学校。
select
device_id,
university
from
user_profile
where
university = "北京大学";
题目:现在运营想要针对24岁以上的用户开展分析,请你取出满足条件的设备ID、性别、年龄、学校。
select
device_id,
gender,
age,
university
from
user_profile
where
age > 24;
题目:现在运营想要针对20岁及以上且23岁及以下的用户开展分析,请你取出满足条件的设备ID、性别、年龄。
select
device_id,
gender,
age
from
user_profile
where
age between 20 and 23;
select
device_id,
gender,
age
from
user_profile
where
age >= 20
and age <= 23;
题目:现在运营想要查看除复旦大学以外的所有用户明细,请你取出相应数据
select
device_id,
gender,
age,
university
from
user_profile
where
university <> "复旦大学";
select
device_id,
gender,
age,
university
from
user_profile
where
university != "复旦大学";
select
device_id,
gender,
age,
university
from
user_profile
where
university not in ("复旦大学");
题目:现在运营想要对用户的年龄分布开展分析,在分析时想要剔除没有获取到年龄的用户,请你取出所有年龄值不为空的用户的设备ID,性别,年龄,学校的信息。
select
device_id,
gender,
age,
university
from
user_profile
where
age is not null;
随手点赞一次,运气增加一份。