diff --git "a/07 \345\206\257\345\273\272\347\250\213/5\343\200\201SELECT\350\257\255\345\217\245\345\237\272\347\241\200\347\273\203\344\271\240.md" "b/07 \345\206\257\345\273\272\347\250\213/5\343\200\201SELECT\350\257\255\345\217\245\345\237\272\347\241\200\347\273\203\344\271\240.md" new file mode 100644 index 0000000000000000000000000000000000000000..44f518222a95f7179e6648f9fe0ee9417b83295c --- /dev/null +++ "b/07 \345\206\257\345\273\272\347\250\213/5\343\200\201SELECT\350\257\255\345\217\245\345\237\272\347\241\200\347\273\203\344\271\240.md" @@ -0,0 +1,132 @@ +# 第1组:user_profile表 + +user_profile表的sql脚本: + +```mysql +drop table if exists user_profile; +CREATE TABLE `user_profile` ( +`id` int, +`device_id` int, +`gender` varchar(14), +`age` int , +`university` varchar(32), +`province` varchar(32)); + + +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'); +``` + +![](5、SELECT语句基础练习.assets/image-20220207141745581 - 副本.png) + +解释:id(编号)、device_id(设备ID),gender(性别),age(年龄)、university(大学名称),province(省份) + +## (1)题目:从用户信息表中取出学校的去重数据 + +现在运营需要查看用户来自于哪些学校,请从用户信息表中取出学校的去重数据。 + +![image-20220207141745581](5、SELECT语句基础练习.assets/image-20220207141745581.png) + +```mysql +select distinct university from user_profile; +``` + + + + + +## (2)题目:查看用户明细设备ID数据,并将列名显示为 'user_infos_example' + +现在你需要查看用户明细设备ID数据,并将列名显示为 'user_infos_example',请你从用户信息表取出相应结果。 + +![image-20220207143458749](5、SELECT语句基础练习.assets/image-20220207143458749.png) + +```mysql +select device_id 'user_infos_example' from user_profile; +``` + +## (3)题目:查询university是北京大学的设备ID + +现在运营想要筛选出所有北京大学的学生进行用户调研,请你从用户信息表中取出满足条件的数据,结果返回设备id和学校。 + +![image-20220207144253185](5、SELECT语句基础练习.assets/image-20220207144253185.png) + +```mysql +select device_id,university from user_profile where university='北京大学'; +``` + + + +## (4)题目:查询年龄大于24用户的设备ID、性别、年龄、学校 + +现在运营想要针对24岁以上的用户开展分析,请你取出满足条件的设备ID、性别、年龄、学校。 + +![image-20220207144628582](5、SELECT语句基础练习.assets/image-20220207144628582.png) + +```mysql +select device_id,gender,age,university from user_profile where age>24; +``` + + + +## (5)题目:查询所有用户的设备id、性别、年龄、学校 + +现在运营同学想要用户的设备id对应的性别、年龄和学校的数据,请你取出相应数据 + +![image-20220207172816753](5、SELECT语句基础练习.assets/image-20220207172816753.png) + +```mysql +select device_id,gender,age,university from user_profile; +``` + + + +## (6)题目:查询所有用户的数据 + +现在运营想要查看用户信息表中所有的数据,请你取出相应结果 + +![image-20220207172840781](5、SELECT语句基础练习.assets/image-20220207172840781.png) + +```mysql +select * from user_profile; +``` + +## (7)题目:查询省份是"shanghai"的用户信息 + +现在运营想要查看上海市用户的信息,请你取出相应的结果。 + +根据示例,你的查询应返回以下结果: + +![image-20220210171353387](5、SELECT语句基础练习.assets/image-20220210171353387.png) + +```mysql +select * from user_profile where province='Shanghai'; +``` + +## (8)题目:查询所有男性用户的设备ID、年龄、学校 + +现在运营想要查看所有男性用户的设备ID、年龄、学校,便于后期做数据分析。 + +根据示例,你的查询应返回如下结果: + +![image-20220210171628263](5、SELECT语句基础练习.assets/image-20220210171628263.png) + +```mysql +select device_id,age,university from user_profile where gender='male'; +``` + +## (9)题目:从用户信息表中取出省份的去重数据 + +现在运营想要查看所有用户的省份分布情况,请从用户信息表中取出省份的去重数据。 + +根据示例,你的查询应返回如下结果: + +![image-20220210171835938](5、SELECT语句基础练习.assets/image-20220210171835938.png) + +```mysql +select distinct province from user_profile; +``` + diff --git "a/07 \345\206\257\345\273\272\347\250\213/6\343\200\201\350\277\220\347\256\227\347\254\246\347\273\203\344\271\240.md" "b/07 \345\206\257\345\273\272\347\250\213/6\343\200\201\350\277\220\347\256\227\347\254\246\347\273\203\344\271\240.md" new file mode 100644 index 0000000000000000000000000000000000000000..835ca6b8b72ca407b8307e264120430fae57fd1f --- /dev/null +++ "b/07 \345\206\257\345\273\272\347\250\213/6\343\200\201\350\277\220\347\256\227\347\254\246\347\273\203\344\271\240.md" @@ -0,0 +1,149 @@ +# 第1题:user_profile表脚本1 + +user_profile表的sql脚本: + +```mysql +drop table if exists user_profile; +CREATE TABLE `user_profile` ( +`id` int, +`device_id` int, +`gender` varchar(14), +`age` int , +`university` varchar(32), +`province` varchar(32)); + +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'); +``` + +![](6、运算符练习.assets/image-20220207141745581 - 副本.png) + +解释:id(编号)、device_id(设备ID),gender(性别),age(年龄)、university(大学名称),province(省份) + +## (1)题目:查询年龄20岁及以上且23岁及以下用户的设备ID、性别、年龄 + +现在运营想要针对20岁及以上且23岁及以下的用户开展分析,请你取出满足条件的设备ID、性别、年龄。 + +![image-20220207144855013](6、运算符练习.assets/image-20220207144855013.png) + +```mysql +select device_id,gender,age from user_profile where age>=20 and age<=23; +``` + + + +## (2)题目:查询除复旦大学以外的所有用户的设备ID、性别、年龄、大学 + +现在运营想要查看除复旦大学以外的所有用户明细,请你取出相应数据 + +![image-20220207144942510](6、运算符练习.assets/image-20220207144942510.png) + +```mysql +select device_id,gender,age,university from user_profile where university!='复旦大学 +``` + + + +## (3)题目:查询年龄不为空的用户的设备ID,性别,年龄,学校的信息 + +现在运营想要对用户的年龄分布开展分析,在分析时想要剔除没有获取到年龄的用户,请你取出所有年龄值不为空的用户的设备ID,性别,年龄,学校的信息。 + +![image-20220207145017152](6、运算符练习.assets/image-20220207145017152.png) + +```mysql +select device_id,gender,age,university from user_profile where age is not null; +``` + +# 第2题:user_profile表脚本2 + +user_profile表sql脚本 + +```mysql +drop table if exists user_profile; +CREATE TABLE `user_profile` ( +`id` int , +`device_id` int, +`gender` varchar(14), +`age` int , +`university` varchar(32), +`gpa` float, +`active_days_within_30` float, +`question_cnt` float, +`answer_cnt` float +); + +INSERT INTO user_profile VALUES(1,2138,'male',21,'北京大学',3.4,7,2,12); +INSERT INTO user_profile VALUES(2,3214,'male',null,'复旦大学',4.0,15,5,25); +INSERT INTO user_profile VALUES(3,6543,'female',20,'北京大学',3.2,12,3,30); +INSERT INTO user_profile VALUES(4,2315,'female',23,'浙江大学',3.6,5,1,2); +INSERT INTO user_profile VALUES(5,5432,'male',25,'山东大学',3.8,20,15,70); +INSERT INTO user_profile VALUES(6,2131,'male',28,'北京师范大学',3.3,15,7,13); +``` + +![image-20220207145932876](6、运算符练习.assets/image-20220207145932876.png) + +解释:id(编号)、device_id(设备ID),gender(性别),age(年龄)、university(大学名称),province(省份),gpa(平均成绩)、active_days_within_30(30天内活跃天数)、question_cnt(发帖数量)、answer_cnt(回答数量) + +例如:第一行表示:id为1的用户的常用信息为使用的设备id为2138,性别为男,年龄21岁,北京大学,gpa为3.4,在过去的30天里面活跃了7天,发帖数量为2,回答数量为12 + +## (4)题目:查询男性且GPA在3.5以上(不包括3.5)的用户的设备ID,性别、年龄、学校、gpa + +现在运营想要找到男性且GPA在3.5以上(不包括3.5)的用户进行调研,请你取出相关数据。 + +![image-20220207145044808](6、运算符练习.assets/image-20220207145044808.png) + +```mysql +select device_id,gender,age,university,gpa from user_profile where gpa>3.5 +``` + + + +## (5)题目:查询学校为北大或GPA在3.7以上(不包括3.7)的用户的设备ID,性别、年龄、学校、gpa + +现在运营想要找到学校为北大或GPA在3.7以上(不包括3.7)的用户进行调研,请你取出相关数据(使用OR实现) + +![image-20220207145119374](6、运算符练习.assets/image-20220207145119374.png) + +```mysql +select device_id,gender,age,university,gpa from user_profile where gpa>3.7 or university='北京大学'; +``` + + + +## (6)题目:查询学校为北大、复旦和山大用户的设备ID,性别、年龄、学校、gpa + +现在运营想要找到学校为北大、复旦和山大的同学进行调研,请你取出相关数据。 + +![image-20220207145152255](6、运算符练习.assets/image-20220207145152255.png) + +```mysql +select device_id,gender,age,university,gpa from user_profile where university in('北京大学','复旦大学','山东大学'); +``` + + + +## (7)题目:查询gpa在3.5以上(不包括3.5)的山东大学用户 或 gpa在3.8以上(不包括3.8)的复旦大学同学 + +现在运营想要找到gpa在3.5以上(不包括3.5)的山东大学用户 或 gpa在3.8以上(不包括3.8)的复旦大学同学进行用户调研,请你取出相应数据。 + +![image-20220207145321717](6、运算符练习.assets/image-20220207145321717.png) + +```mysql +select device_id,gender,age,university,gpa from user_profile where gpa>3.5 and university='山东大学' or gpa>3.8 and university='复旦大学'; +``` + + + +## (8)题目:所有大学中带有北京的用户信息 + +现在运营想查看所有大学中带有北京的用户的信息,请你取出相应数据。 + +![image-20220207145355354](6、运算符练习.assets/image-20220207145355354.png) + +```mysql +select device_id,age,university from user_profile where university like '%北京%'; +``` +