Summary of MySQL interview questions (part)

                             

                      1. Introduce why MySQL is mentioned in the interview

1. Why is MySQL mentioned in the interview?

There are several main reasons for asking MySQL questions in interviews :

1. The importance of the database management system : As a commonly used relational database management system (RDBMS), MySQL is widely used in Internet and enterprise applications. Understanding and proficiency in database is one of the necessary skills for a qualified software developer. By asking MySQL questions, interviewers can assess the candidate's understanding and experience with database management systems.

2. Requirements for database-related work : Many positions, especially those related to back-end development and data engineering, require candidates to have database-related knowledge and experience. Asking MySQL questions during the interview process can help the interviewer assess whether the candidate meets the requirements of the job and judge its ability in database design, optimization and tuning.

3. Inspection of comprehensive technical capabilities : MySQL issues not only focus on the database itself, but also involve knowledge of SQL language, query optimization, transaction processing, and index design. By asking MySQL questions, the interviewer can test the applicant's comprehensive technical ability, including basic knowledge of database, proficiency in SQL language and ability to solve problems.

In summary, the purpose of asking MySQL questions in an interview is to assess the candidate's database knowledge and skills, as well as their ability to design, manage, and optimize databases. These questions can help interviewers judge whether candidates are suitable for database-related positions and can perform related tasks.

2. Learn the importance of MySQL database 

Learning the MySQL database has the following importance:

1. Data storage and management : MySQL is a mature, stable and widely used relational database management system (RDBMS). Learning MySQL can enable you to store and manage large amounts of structured data, whether it is a personal project or an enterprise-level application, it helps to organize and manipulate data effectively.

2. Back-end development and data engineering : MySQL is one of the commonly used databases in back-end development and data engineering. Learning MySQL can equip you with the key skills needed to build and maintain applications, including database design, data modeling, query optimization, index optimization, transaction processing, and more. These skills are critical to developing high-performance, reliable applications.

3. Data analysis and decision support : With the continuous growth of data, data analysis and decision support become more and more important. MySQL has powerful query and analysis functions that can help you extract, organize, and analyze data to support business decisions and insight discovery. Learning the data analysis capabilities of MySQL can give you a competitive edge in a data-driven environment.

4. Software engineering practice : Learning and mastering MySQL as a popular open source database can enable you to better understand the principles and best practices of database development in software engineering. This includes knowledge of database design paradigms, normalization and denormalization, performance optimization, data security, and more. This is critical to building scalable, efficient and secure applications.

5. Career development and employment opportunities : Database management and data engineering is one of the important career fields in the IT industry. Having MySQL database skills can open up many career opportunities for you, whether in roles such as backend developer, data engineer, database administrator, or data analyst. Learning MySQL can improve your competitiveness in the job market.

All in all, learning the MySQL database is very important for software developers and data engineers. It is one of the key tools for building applications, processing and analyzing data, with a wide range of application scenarios and career opportunities. Whether you are a beginner or an experienced developer, mastering MySQL database skills will have major benefits in your career advancement.

3. Summary 

     No matter which method you take on the road of learning Java, data operation and management are very important. Learning and being good at databases can make you faster than others on the road to employment.
     Another thing I want to say is, learn more things that others don't know. What is value? To put it simply: For example, if you can, you will, and you will also do what others can't, and you can do better than others, this is your value!


                                         2. Interview questions

1. Oral interview (partial)

1.1. What is MySQL? How does it work?

   Answer: MySQL is an open source relational database management system (RDBMS) that uses a client/server model. The client connects to the database server through the network and sends SQL queries to access and manipulate the data in the database.

1.2. What are the storage engines in MySQL? What's the difference?  

 Answer: MySQL supports multiple storage engines, including InnoDB, MyISAM, Memory, etc. These storage engines differ in performance, reliability, transaction support, and more. InnoDB is the default storage engine of MySQL, which supports transactions and row-level locking, and is suitable for most application scenarios.

1.3. What is an index? Why are indexes used in databases?

Answer: An index is a data structure in a database that can speed up query operations. Indexes can improve query efficiency and reduce query time complexity. They can locate the required data more quickly without scanning the entire table.

1.4. What is a transaction? How does MySQL support transactions?

 Answer: A transaction is a set of database operations that are considered atomic, that is, either all of them are executed successfully, or all of them are rolled back to the initial state. MySQL supports transactions by using ACID properties (atomicity, consistency, isolation, and durability). Transactions can be explicitly started, committed, and rolled back in MySQL by using the BEGIN, COMMIT, and ROLLBACK statements.

1.5. What is SQL injection? How to avoid SQL injection attacks?

 Answer: SQL injection is a common security vulnerability. Hackers insert malicious code into SQL queries entered by users, thereby affecting the operation of the database. To avoid SQL injection attacks, the most important thing is to use parameterized queries or prepared statements to process user input instead of directly splicing the values ​​entered by users into SQL statements.

This is just a small part of the MySQL interview questions, I hope to help you. If you have any specific questions, or need more interview questions, feel free to let me know!

2. Machine test (partial)

2.1 Script

一、表结构要求:

-- 1.学生表-t_mysql_student
-- sid 学生编号,sname 学生姓名,sage 学生年龄,ssex 学生性别

-- 2.教师表-t_mysql_teacher
-- tid 教师编号,tname 教师名称

-- 3.课程表-t_mysql_course
-- cid 课程编号,cname 课程名称,tid 教师名称

-- 4.成绩表-t_mysql_score
-- sid 学生编号,cid 课程编号,score 成绩

二、表数据:

-- 学生表
insert into t_mysql_student values('01' , '赵雷' , '1990-01-01' , '男');
insert into t_mysql_student values('02' , '钱电' , '1990-12-21' , '男');
insert into t_mysql_student values('03' , '孙风' , '1990-12-20' , '男');
insert into t_mysql_student values('04' , '李云' , '1990-12-06' , '男');
insert into t_mysql_student values('05' , '周梅' , '1991-12-01' , '女');
insert into t_mysql_student values('06' , '吴兰' , '1992-01-01' , '女');
insert into t_mysql_student values('07' , '郑竹' , '1989-01-01' , '女');
insert into t_mysql_student values('09' , '张三' , '2017-12-20' , '女');
insert into t_mysql_student values('10' , '李四' , '2017-12-25' , '女');
insert into t_mysql_student values('11' , '李四' , '2012-06-06' , '女');
insert into t_mysql_student values('12' , '赵六' , '2013-06-13' , '女');
insert into t_mysql_student values('13' , '孙七' , '2014-06-01' , '女');

-- 教师表
insert into t_mysql_teacher values('01' , '张三');
insert into t_mysql_teacher values('02' , '李四');
insert into t_mysql_teacher values('03' , '王五');

-- 课程表
insert into t_mysql_course values('01' , '语文' , '02');
insert into t_mysql_course values('02' , '数学' , '01');
insert into t_mysql_course values('03' , '英语' , '03');

-- 成绩表
insert into t_mysql_score values('01' , '01' , 80);
insert into t_mysql_score values('01' , '02' , 90);
insert into t_mysql_score values('01' , '03' , 99);
insert into t_mysql_score values('02' , '01' , 70);
insert into t_mysql_score values('02' , '02' , 60);
insert into t_mysql_score values('02' , '03' , 80);
insert into t_mysql_score values('03' , '01' , 80);
insert into t_mysql_score values('03' , '02' , 80);
insert into t_mysql_score values('03' , '03' , 80);
insert into t_mysql_score values('04' , '01' , 50);
insert into t_mysql_score values('04' , '02' , 30);
insert into t_mysql_score values('04' , '03' , 20);
insert into t_mysql_score values('05' , '01' , 76);
insert into t_mysql_score values('05' , '02' , 87);
insert into t_mysql_score values('06' , '01' , 31);
insert into t_mysql_score values('06' , '03' , 34);
insert into t_mysql_score values('07' , '02' , 89);
insert into t_mysql_score values('07' , '03' , 98);

2.2 Topics

1. Query the information and course scores of students whose grades in the course "01" are higher than those in the course "02"

Idea: query the corresponding results of the 01 course, query the corresponding results of the 02 course, and compare the intersection of the two results) 

select t3.*,t1.score 01课程,t2.score 02课程 from 
(select * from t_mysql_score where cid='01')t1,
(select * from t_mysql_score where cid='02')t2,
t_mysql_student t3 
where t1.sid=t2.sid and t1.sid=t3.sid 
and t1.score>t2.score 

2. Query the situation that "01" and "02" courses exist at the same time

Idea: Query the situation of two courses at the same time, in fact, it is to query the students who study two courses among all students, and then filter

select t3.*,t1.score 01课程,t2.score 02课程 from 
(select * from t_mysql_score where cid='01')t1,
(select * from t_mysql_score where cid='02')t2,
t_mysql_student t3 
where t1.sid=t2.sid and t1.sid=t3.sid


3. Query the situation where "01" course exists but "02" course may not exist (if it does not exist, it will be displayed as null)

Ideas: 1. Course 01 must exist 2. Dispensable

select t1.*,t2.score from 
(select *from t_mysql_score where cid='01')t1 left join
(select *from t_mysql_score where cid='02')t2 on
t1.sid=t2.sid


04) Query if there is no "01" course but there is a "02" course

Ideas: 1. Must have 02 course 2. Cannot have 01 course

select *from t_mysql_score sc where sc.sid not in 
(select sid from t_mysql_score where cid='01')and cid='02'


05) Query the student number, student name and average grade of the students whose average grade is greater than or equal to 60

Idea: 1. Use the student number and student name as grouping fields 2. Query the average grade of students according to the student number and student name

select 
s.sid,s.sname,ROUND(AVG(sc.score),2)
from 
t_mysql_score sc,t_mysql_student s
where
sc.sid=s.sid 
GROUP BY
s.sid,s.sname 
HAVING
AVG(sc.score)>=60


06) Query the student information with grades in the t_mysql_score table

select s.sid,s.sname from t_mysql_student s ,t_mysql_score sc where s.sid=sc.sid and sc.score is not null 
GROUP BY s.sid,s.sname


07) Query the student number, student name, total number of courses selected, and total grades of all courses of all students (the ones without grades are displayed as null)

Ideas: 1. Use student number and student name as grouping fields 2.count, sum

select
s.sid,s.sname,COUNT(sc.cid),SUM(sc.score)
from 
t_mysql_score sc,t_mysql_student s
where 
sc.sid=s.sid
GROUP BY
s.sid,s.sname


08) Query the number of teachers with the surname "Li"

select count(*) from t_mysql_teacher where tname like '李%'


09) Query the information of the students who have learned from the teacher "Zhang San"

SELECT
s.*,c.cname,t.tname
FROM
t_mysql_teacher t,t_mysql_student s,t_mysql_course c,t_mysql_score sc
WHERE
t.tid=c.tid and c.cid=sc.cid and sc.sid=s.sid and tname = '张三'


10) Query the information of students who have not studied all courses


SELECT
s.sid,s.sname,count(sc.score) n
FROM
t_mysql_score sc,t_mysql_student s
WHERE
sc.sid=s.sid
GROUP BY
s.sid,s.sname
HAVING
n<(select count(c.cid) from t_mysql_course c )


11) Query the names of students who have not studied any course taught by "Zhang San"

Idea: 1. Query the students who have studied the course of Mr. Zhang San 2. not in

select s.* from t_mysql_student s where s.sid not in(
SELECT
sc.sid
FROM
t_mysql_teacher t,t_mysql_course c,t_mysql_score sc
WHERE
t.tid=c.tid and c.cid=sc.cid and t.tname='张三'
GROUP BY
sc.sid)


12) Query the student ID, name and average grade of students who have failed two or more courses

SELECT
s.sid,s.sname,ROUND(AVG(sc.score)) 平均成绩,COUNT(sc.cid) n
FROM
t_mysql_student s,t_mysql_score sc
WHERE
s.sid=sc.sid and sc.score<60
GROUP BY
s.sid,s.sname
HAVING
n>=2


13) Retrieve the "01" course score less than 60, the student information in descending order of score

SELECT
s.*
FROM
t_mysql_score sc,t_mysql_student s
WHERE
sc.sid=s.sid and sc.score<60 and cid='01'
ORDER BY sc.score DESC


14) Display the grades and average grades of all courses for all students in order of average grades from high to low

Ideas: Query student information, course information, student grades for each course, and student average grades

SELECT
s.sid,s.sname,round(AVG(sc.score),2) avgNum ,
max(case when sc.cid='01' then sc.score end)语文,
max(case when sc.cid='02' then sc.score end)数学,
max(case when sc.cid='03' then sc.score end)英语
FROM
t_mysql_score sc,t_mysql_student s,t_mysql_course c
WHERE
 sc.sid=s.sid and sc.cid=c.cid
GROUP BY
s.sid,s.sname
ORDER BY avgNum desc


SELECT
s.sid,s.sname,round(AVG(sc.score),2) avgNum ,
max(if(sc.cid='01',sc.score,0))语文,
max(if(sc.cid='02',sc.score,0))数学,
max(if(sc.cid='03',sc.score,0))英语
FROM
t_mysql_score sc,t_mysql_student s,t_mysql_course c
WHERE
 sc.sid=s.sid and sc.cid=c.cid
GROUP BY
s.sid,s.sname
ORDER BY avgNum desc


15) Query the highest score, the lowest score and the average score of each subject:
display in the following form: course ID, course name, highest score, lowest score, average score, pass rate, average rate, excellent rate, excellent rate: >=60, medium: 70-80, excellent: 80-90, excellent: >=90. 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
.

Ideas:

1.max,min,avg

2. Use the course ID and course name as grouping fields
3. Obtain the number of passers, middle people, excellent people, and excellent people

SELECT
c.cid,c.cname,max(sc.score)最高分,
min(sc.score)最低分,
ROUND(AVG(sc.score))平均分,
count(sc.score)选修人数,
CONCAT(ROUND(sum(if(sc.score>=60,1,0))/count(sc.score)*100),'%')及格率,
CONCAT(ROUND(sum(if(sc.score>=70 and sc.score<80,1,0))/count(sc.score)*100),'%')中等率,
CONCAT(ROUND(sum(if(sc.score>=80 and sc.score<90,1,0))/count(sc.score)*100),'%')优良率,
CONCAT(ROUND(sum(if(sc.score>=90,1,0))/count(sc.score)*100),'%')优秀率
FROM
t_mysql_score sc,t_mysql_course c,t_mysql_student s
WHERE
sc.sid=s.sid and sc.cid=c.cid
GROUP BY
c.cid,c.cname
ORDER BY
选修人数 desc,
c.cid

Guess you like

Origin blog.csdn.net/lz17267861157/article/details/131613601