既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上大数据知识点,真正体系化!
由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新
一、高级查询
1、分组查询
1.1 SQL18 分组计算练习题
- 描述
题目:现在运营想要对每个学校不同性别的用户活跃情况和发帖数量进行分析,请分别计算出每个学校每种性别的用户数、30天内平均活跃天数和平均发帖数量。
- 示例1
输入:
drop table if exists user_profile;
CREATE TABLEuser_profile
(
id
int NOT NULL,
device_id
int NOT NULL,
gender
varchar(14) NOT NULL,
age
int ,
university
varchar(32) NOT NULL,
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);
INSERT INTO user_profile VALUES(7,4321,‘male’,28,‘复旦大学’,3.6,9,6,52);
输出:
male|北京大学|1|7.0|2.0
male|复旦大学|2|12.0|5.5
female|北京大学|1|12.0|3.0
female|浙江大学|1|5.0|1.0
male|山东大学|2|17.5|11.0
输入:
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,
`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);
INSERT INTO user_profile VALUES(7,4321,'male',28,'复旦大学',3.6,9,6,52);
输出:
male|北京大学|1|7.0|2.0
male|复旦大学|2|12.0|5.5
female|北京大学|1|12.0|3.0
female|浙江大学|1|5.0|1.0
male|山东大学|2|17.5|11.0
1.1.1 SQL语句(第一种解法)
select
gender,
university,
count(gender) user_num,
round(
sum(active_days_within_30) / count(active_days_within_30),
1
) avg_actie_day,
round(sum(question_cnt) / count(question_cnt), 1) avg_question_cnt
from
user_profile
group by
gender,
university
![在这里插入代码片](https://img-blog.csdnimg.cn/21d71970ec794ab5b7f94b4937e5d7cf.png)
1.1.1 SQL语句(第二种解法推荐)
select
gender,
university,
count(gender) as user_num,
round(avg(active_days_within_30), 1) as avg_active_day,
round(avg(question_cnt), 1) as avg_question_cnt
from
user_profile
group by
gender,
university
select
gender,
university,
count(gender) as user_num,
round(avg(active_days_within_30), 1) as avg_active_day,
round(avg(question_cnt), 1) as avg_question_cnt
from
user_profile
group by
gender,
university
1.2 SQL19 分组过滤练习题
- 描述
题目:现在运营想查看每个学校用户的平均发贴和回帖情况,寻找低活跃度学校进行重点运营,请取出平均发贴数低于5的学校或平均回帖数小于20的学校。
- 示例1
输入:
drop table if exists user_profile;
CREATE TABLEuser_profile
(
id
int NOT NULL,
device_id
int NOT NULL,
gender
varchar(14) NOT NULL,
age
int ,
university
varchar(32) NOT NULL,
gpa
float,
active_days_within_30
int ,
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);
INSERT INTO user_profile VALUES(7,4321,‘male’,28,‘复旦大学’,3.6,9,6,52);
输出:
university|avg_question_cnt|avg_answer_cnt
北京大学|2.500|21.000
浙江大学|1.000|2.000
输入:
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,
`gpa` float,
`active\_days\_within\_30` int ,
`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);
INSERT INTO user_profile VALUES(7,4321,'male',28,'复旦大学',3.6,9,6,52);
输出:
university|avg_question_cnt|avg_answer_cnt
北京大学|2.500|21.000
浙江大学|1.000|2.000
1.2.1 SQL语句(第一种解法)
select
university,
round(sum(question_cnt) / count(question_cnt), 3) avg_question_cnt,
round(sum(answer_cnt) / count(answer_cnt), 3) avg_answer_cnt
from
user_profile
group by
university
having
round(sum(question_cnt) / count(question_cnt), 3) < 5
or round(sum(answer_cnt) / count(answer_cnt), 3) < 20
select
university,
round(sum(question_cnt) / count(question_cnt), 3) avg_question_cnt,
round(sum(answer_cnt) / count(answer_cnt), 3) avg_answer_cnt
from
user_profile
group by
university
having
round(sum(question_cnt) / count(question_cnt), 3) < 5
or round(sum(answer_cnt) / count(answer_cnt), 3) < 20
1.2.2 SQL语句(第二种解法推荐)
select
university,
round(avg(question_cnt), 3) avg_question_cnt,
网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
…(img-TFSHSqHp-1715369896666)]
[外链图片转存中…(img-afLKjDRZ-1715369896666)]
网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!