2023 full network Mysql collection (25w words) with courses from installation to advanced, actual combat

mysql learning

1. Install mysql

Installation Tutorial

2. Detailed learning tutorial of mysql

Detailed tutorial of mysql

Please add a picture description

3. Advanced optimization of mysql

Advanced MySQL (SQL optimization, index optimization, lock mechanism, master-slave replication)

4. MySQL interview

Summary of MySQL database interview questions

Two. mysql actual combat

1. Create a data table and insert data

1. Student table
Student(s_id, s_name, s_birth, s_sex): student number, name, year, month, gender

-- 1、学生表
-- Student(s_id,s_name,s_birth,s_sex) :学生编号、姓名、年月、性别
CREATE TABLE
IF NOT EXISTS `Student` (
	`s_id` VARCHAR (20),
	`s_name` VARCHAR (20) NOT NULL DEFAULT '',
	`s_birth` VARCHAR (20) NOT NULL DEFAULT '',
	`s_sex` VARCHAR (10) NOT NULL DEFAULT '',
	PRIMARY KEY (`s_id`)
) ENGINE = INNODB DEFAULT CHARSET = utf8;
-- 插入数据
INSERT INTO Student VALUES ('01', '赵雷', '1990-01-01', '男');
INSERT INTO Student VALUES ('02', '钱电', '1990-12-21', '男');
INSERT INTO Student VALUES ('03', '孙风', '1990-05-20', '男');
INSERT INTO Student VALUES ('04', '李云', '1990-08-06', '男');
INSERT INTO Student VALUES ('05', '周梅', '1991-12-01', '女');
INSERT INTO Student VALUES ('06', '吴兰', '1992-03-01', '女');
INSERT INTO Student VALUES ('07', '郑竹', '1989-07-01', '女');
INSERT INTO Student VALUES ('08', '王菊', '1990-01-20', '女');

2. Curriculum
Course(c_id,c_name,t_id): course number, course name, teacher number

-- 2、课程表
-- Course(c_id,c_name,t_id) :课程编号、 课程名称、 教师编号
CREATE TABLE
IF NOT EXISTS `Course` (
	`c_id` VARCHAR (20),
	`c_name` VARCHAR (20) NOT NULL DEFAULT '',
	`t_id` VARCHAR (20) NOT NULL,
	PRIMARY KEY (`c_id`)
) ENGINE = INNODB DEFAULT CHARSET = utf8;
-- 插入数据
INSERT INTO Course VALUES ('01', '语文', '02');
INSERT INTO Course VALUES ('02', '数学', '01');
INSERT INTO Course VALUES ('03', '英语', '03');

3. Teacher table
Teacher(t_id,t_name): teacher ID, teacher name

-- 3、教师表
-- Teacher(t_id,t_name) :教师编号、教师姓名
CREATE TABLE
IF NOT EXISTS `Teacher` (
	`t_id` VARCHAR (20),
	`t_name` VARCHAR (20) NOT NULL DEFAULT '',
	PRIMARY KEY (`t_id`)
) ENGINE = INNODB DEFAULT CHARSET = utf8;
-- 插入数据
INSERT INTO Teacher VALUES ('01', '张三');
INSERT INTO Teacher VALUES ('02', '李四');
INSERT INTO Teacher VALUES ('03', '王五');

4. Score table
Score(s_id,c_id,s_score): student number, course number, score

-- 4、成绩表
-- Score(s_id,c_id,s_score) :学生编号、课程编号、分数
CREATE TABLE
IF NOT EXISTS `Score` (
	`s_id` VARCHAR (20),
	`c_id` VARCHAR (20),
	`s_score` INT (3),
	PRIMARY KEY (`s_id`, `c_id`)
) ENGINE = INNODB DEFAULT CHARSET = utf8;
-- 插入数据
INSERT INTO Score VALUES ('01', '01', 80);
INSERT INTO Score VALUES ('01', '02', 90);
INSERT INTO Score VALUES ('01', '03', 99);
INSERT INTO Score VALUES ('02', '01', 70);
INSERT INTO Score VALUES ('02', '02', 60);
INSERT INTO Score VALUES ('02', '03', 80);
INSERT INTO Score VALUES ('03', '01', 80);
INSERT INTO Score VALUES ('03', '02', 80);
INSERT INTO Score VALUES ('03', '03', 80);
INSERT INTO Score VALUES ('04', '01', 50);
INSERT INTO Score VALUES ('04', '02', 30);
INSERT INTO Score VALUES ('04', '03', 20);
INSERT INTO Score VALUES ('05', '01', 76);
INSERT INTO Score VALUES ('05', '02', 87);
INSERT INTO Score VALUES ('06', '01', 31);
INSERT INTO Score VALUES ('06', '03', 34);
INSERT INTO Score VALUES ('07', '02', 89);
INSERT INTO Score VALUES ('07', '03', 98);

select * FROM course
insert image description here

select * FROM score
insert image description here

select * FROM student
insert image description here

select * FROM teacher
insert image description here

course

50 course lectures

2. Start to solve the problem

2.1 Topic 1: Query the information and course scores of students with higher grades in course "01" than course "02"


2.2 Topic 2: Query the student numbers, student names and average grades of students whose average grades are greater than or equal to 60 points and the total score is greater than 200 points, and who must take 3 courses Name, average grade (including those with and without grades)
2.4 Topic 4: Query the student number, student name, total number of courses taken, and total grades of all courses
2.5 Topic 5: Query the number of teachers with the surname "Li"
2.6 Topic 6
2.7 Topic 7: Find out the students who have not taken the course taught by Zhang San 2.8
Topic 8: Query the information of students who have taken the course number 01 and 02
2.9 Topic 9 : Query the information of students who have studied the course 01 but not the course 02 2.10
Topic 10: Query the information of students who have not completed all the courses
2.11 Topic 11: Query at least one course that is the same as that of the students with the student number 01 Classmate information
2.12 Topic 12: Query the information of students who have the same course as classmate 01
2.13 Topic 13: Query the names of students who have not taken any course taught by Mr. Zhang San
2.14 Topic 14: Query two or more courses The student number, name and average grade of the students who failed the course
2.15 Topic 15: The second question of LeetCode-for-SQL: The second highest salary
2.16 Topic 16: Find the nth highest grade (find the Chinese subject No. 2 high grades and student numbers)
2.17 Topic 17: LeetCode-SQL-596 - Courses with more than 5 students
2.18 Topic 18: LeetCode-SQL-181 - Employees earning more than managers
2.19 Topic 19: Retrieve the student information of course 01 whose score is less than 60, sorted by score in descending order
2.20 Topic 20: Display the grades and average grades of all courses of all students according to the average grade from high to low (descending order)
2.21 Topic 21: Query each subject Highest score, lowest score and average score: displayed in the following form: course ID, course name, highest score, lowest score, average score, pass rate (pass: >=60), medium rate (medium: 70-80) , excellent rate (excellent: 80-90), excellent rate (excellent: >=90); —Comparative comprehensive, read more!
2.22 Topic 22: Sorting according to the results of each subject, and displaying the ranking—comprehensive, read more!
2.23 Topic 23: Query the students' total grades and rank them—comprehensive, read more!
2.24 Topic 24: LeetCode-SQL-182-Find duplicate emails, find duplicate emails from the given table Person
2.25 Topic 25: LeetCode-SQL-595-Big Country
2.26 Topic 26: LeetCode-SQL- 184-Employees with the highest salary/highest salary in the department—see more
2.27 Topic 27: Query the average scores of different courses taught by different teachers from high to low and display
2.28 Topic 28: Query the information of students who rank 2nd to 3rd in all courses And the course score
2.29 Topic 29: Count the number of people in each grade of each subject: course number, course name, [100-85], [85-70], [70-60], [0-60] and the percentage
2.30 Topic 30: Query students’ average grades and rankings—comprehensively, read more, define variables, and implement the rank function
2.31 Topic 31: Query the top three records of each subject—comparatively, see more
2.32 Topic 32: Query each subject Number of students taking the course
2.33 Topic 33: Query the student numbers and names of all students with only two courses
2.34 Topic 34: Query the number of male and female students 2.35 Topic 35: Query the information of students whose
names contain the word Feng
And count the number of people with the same name
2.37 Topic 37: Query the average grade of each course, and the results are arranged in descending order of average grade
; , name and average grade
2.39 Topic 39: Query the courses and scores (average score, total score) of all students
2.40 Topic 40: Query the information and grades of the students with the highest grades among the students who have taken courses taught by teacher "Zhang San"
2.41 Topic 41: Query the student number, course number, and student grades of students with the same grades in different courses—more comprehensive, read more! A table from
2.42 Topic 42: The requirement of the topic is to find out the top 2 students of each course - read more, compare comprehensively, and solve the problem of ranking the top few
2.43 Topic 43: Count the number of students taking each course (more than Only courses with 5 students are counted). It is required to output the course number and the number of electives. The query results are arranged in descending order of the number of people. If the number of people is the same, they are arranged in ascending order of the course number. 2.44 Topic 44: Retrieve the student IDs of
at least two courses 2.46 Topic 46: Query the age of each student: Calculate according to the date of birth. If the current month and day < the month and day of the year of birth, the age will be reduced by 1. 2.47 Topic 47: Query the students who have a birthday this week Birthday students 2.49 Topic 49: Query students who have passed birth this month





2.50 Topic 50: Query students who will be born in the next month

Guess you like

Origin blog.csdn.net/leader_song/article/details/132348182