数据表介绍1:
用户信息表:user_profile
其中device_id指终端编号(每个用户有唯一的一个终端),gender指性别,age指年龄,university指用户所在的学校,gpa是该用户平均学分绩点,active_days_within_30是30天内的活跃天数。
建表:
drop table if exists user_profile;
CREATE TEMP 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,
gpa float);
INSERT INTO user_profile VALUES(1,2138,'male',21,'北京大学','BeiJing',3.4);
INSERT INTO user_profile VALUES(2,3214,'male',null,'复旦大学','Shanghai',4.0);
INSERT INTO user_profile VALUES(3,6543,'female',20,'北京大学','BeiJing',3.2);
INSERT INTO user_profile VALUES(4,2315,'female',23,'浙江大学','ZheJiang',3.6);
INSERT INTO user_profile VALUES(5,5432,'male',25,'山东大学','Shandong',3.8);
INSERT INTO user_profile VALUES(1,2234,'male',21,'北京大学','BeiJing',3.2);
INSERT INTO user_profile VALUES(2,2235,'male',null,'复旦大学','Shanghai',3.8);
INSERT INTO user_profile VALUES(3,2236,'female',20,'复旦大学','Shanghai',3.5);
INSERT INTO user_profile VALUES(4,2237,'female',23,'浙江大学','ZheJiang',3.3);
INSERT INTO user_profile VALUES(5,2238,'male',25,'复旦大学','Shanghai',3.1);
INSERT INTO user_profile VALUES(6,2239,'male',25,'北京大学','BeiJing',3.6);
INSERT INTO user_profile VALUES(7,2240,'male',null,'清华大学','BeiJing',3.3);
INSERT INTO user_profile VALUES(8,2241,'female',null,'北京大学','BeiJing',3.7);
练习1:入门(简单)
1.查看用户信息表中所有的数据:
select * from user_profile;
2.取出用户的设备id对应的性别、年龄和学校的数据:
select device_id,gender,age,university from user_profile;
3.取出学校的去重数据:
select distinct(university) from user_profile;
4.查看前2个用户明细设备ID数据:
select device_id from user_profile limit 2;
5.查看前2个用户明细设备ID数据,并将列名改为 ‘user_infos_example’:
select device_id as user_infos_example from user_profile limit 2;
6.筛选出所有北京大学的学生,返回设备id和学校:
select device_id,university from user_profile where university=‘北京大学’;
7.针对24岁以上的用户开展分析,取出满足条件的设备ID、性别、年龄、学校:
select device_id,gender,age,university from user_profile where age>24;
8.针对20岁及以上且23岁及以下的用户开展分析,请你取出