当前位置:网站首页>MySQL small exercise (only suitable for beginners, non beginners are not allowed to enter)
MySQL small exercise (only suitable for beginners, non beginners are not allowed to enter)
2022-04-23 08:53:00 【A little white who loves programming】
Personal home page : Personal home page
Series column :MySQL database
ha-ha , This is our teacher's assignment , I was thinking about whether to blog or not ?
Finally, I thought about , Let's send it out , Although it's very simple , But you can practice it for those who have just learned database . Because there is no answer , I don't know , If a big man finds a mistake , Please point out .
subject :
- Check the student number of each student 、 Class and name
- Query all the information of the course
- Query the professional classes in the database
- Query class hours greater than 60 Course information for
- Check the date of birth 1986 The student number of the student born in 、 Name and date of birth
- The results of three inquiries are in 80 Student numbers with scores above 、 Course no.
- Check the student number of the student surnamed Zhang 、 Name and major class
- Inquire about 05 Class boy information
Query the student number and course number without homework score
- The student ID is 0538 Students' homework 1 Total score
- Check the elective course K001 Number of students in the course
- How many databases are there in the class
- Query more than three elective courses ( contain 3 door ) The student number and homework of the students in the course 1 average , Homework 2 average , Homework 3 average



If the partners are 0 Basics It doesn't matter , Take a look at this blog Then I'll do the question .
1. Create database
create database if not exists db2 ;


Well, it was created successfully , Then we open the console
2. Create table
1. Create student table

analysis :
Student number : Character
full name : Character
Gender : Character Gender is a word therefore varchar(1)
Professional class : Character
Date of birth : Time type date
contact number : Character Phone number 11 position varchar(11) that will do .
drop table if exists student;
create table student
(
id varchar(10) comment ' Student number ',
name varchar(10) NOT NULL comment ' full name ',
gender char(1) comment ' Gender ',
class varchar(20) comment ' Professional class ',
date date comment ' Date of birth ',
iphone varchar(11) comment ' contact number '
)
comment ' Student list ';
select * from student;

2. Create a curriculum

drop table if exists student_course;
create table student_course
(
course_id varchar(10) comment ' Course no. ',
course_name varchar(15) comment ' Course name ',
course_number double unsigned comment ' Grades ',
student_time int unsigned comment ' Class hours ',
teacher varchar(10) comment ' The teacher '
)
comment ' The curriculum ';
select *
from student_course;

3. Student homework sheet

drop table if exists student_homework;
create table student_homework
(
course_id varchar(10) comment ' Course no. ',
id varchar(10) comment ' Student number ',
homework_1 int comment ' Homework 1 achievement ',
homework_2 int comment ' Homework 2 achievement ',
homework_3 int comment ' Homework 3 achievement '
)
comment ' Student homework sheet ';
select *
from student_homework;

3. Add data
Print out one by one according to the data on the picture , Purring
1. Student list 
insert into student
values ('0433', ' Zhang Yan ', ' Woman ', ' biological 04', '1986-9-13', null),
('0496', ' Li Yue ', ' male ', ' Electronics 04', '1984-2-23', '1381290xxxx'),
('0529', ' Zhao Xin ', ' male ', ' accounting 05', '1984-1-27', '1350222xxxx'),
('0531', ' Zhang Zhiguo ', ' male ', ' biological 05', '1986-9-10', '1331256xxxx'),
('0538', ' Yu Lanlan ', ' Woman ', ' biological 05', '1984-2-20', '1331200xxxx'),
('0591', ' Wang Lili ', ' Woman ', ' Electronics 05', '1984-3-20', '1332080xxxx'),
('0592', ' Wang Haiqiang ', ' male ', ' Electronics 05', '1986-11-1', null);
Check it out. :
select * from student;

2. The curriculum

INSERT INTO student_course
values ('K001', ' Computer graphics ', 2.5, 40, ' Hu Jingjing '),
('K002', ' Fundamentals of computer application ', 3, 48, ' Quan Ren '),
('K006', ' data structure ', 4, 64, ' Ma Yuexian '),
('M001', ' Political economy ', 4, 64, ' Kong fanxin '),
('S001', ' Advanced mathematics ', 3, 48, ' Zhao Xiaochen ');
Check it out. :
select *
from student_course;

3. Student homework sheet

insert into student_homework values
('K001','0433',60,75,75),
('K001','0529',70,70,60),
('K001','0531',70,80,80),
('K001','0591',80,90,90),
('K002','0496',80,80,90),
('K002','0529',70,70,85),
('K002','0531',80,80,80),
('K002','0538',65,75,85),
('K002','0592',75,85,85),
('K006','0531',80,80,90),
('K006','0591',80,80,80),
('M001','0496',70,70,80),
('M001','0591',65,75,75),
('S001','0531',80,80,80),
('S001','0538',60,null,80);
Check it out. :
select *
from student_homework;

4. Start to work on the questions
1. Check the student number of each student 、 Class and name
select id,class,name from student;

2. Query all the information of the course
select *
from student_course;

3. Query the professional classes in the database
select class from student;

4. Query class hours greater than 60 Course information for
select course_id,course_name from student_course where student_time>60;

5. Check the date of birth 1986 The student number of the student born in 、 Name and date of birth
select id,name,date from student where date>=('1986-1-1') AND date<('1987-1-1');

6. The results of three inquiries are in 80 Student numbers with scores above 、 Course no.
At first, I used this to query :
select * from student_homework where homework_1>80 and homework_2>80 and homework_3>80;
Found nothing , So I looked at the data It is found that the results of three assignments are 80 Score more than There is no such data
Therefore, this topic :“ The results of three inquiries are in 80 Student numbers with scores above 、 Course no. ” should Include 80 branch
therefore , I'll change it :
select * from student_homework where homework_1>=80 and homework_2>=80 and homework_3>=80;
7. Check the student number of the student surnamed Zhang 、 Name and major class
Error model :
Because I haven't written for hundreds of years SQL 了 , I wrote ( Give yourself a slap ):
select id,name,class from student where name = ' Zhang %';
select id,name,class from student where name like ' Zhang %';

8. Inquire about 05 Class boy information
select * from student where class like '%05' and gender=' male ';

9. Query the student number and course number without homework score
select id,course_id from student_homework where homework_1 is null or homework_2 is null or homework_3 is null ;

10. The student ID is 0538 Students' homework 1 Total score
select sum(homework_1) ' Total score ' from student_homework where id='0538';

11. Check the elective course K001 Number of students in the course
select count(*) from student_homework where course_id='K001';

12. How many databases are there in the class
select count(*) from student where class is not null ;

13. Query more than three elective courses ( contain 3 door ) The student number and homework of the students in the course 1 average , Homework 2 average , Homework 3 average
select student.id, avg(homework_1), avg(homework_2), avg(homework_3)
from student
left join student_homework on student.id = student_homework.id
group by student.id
having count(course_id) >= 3;

版权声明
本文为[A little white who loves programming]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230850315895.html
边栏推荐
- 请提前布局 Star Trek突破链游全新玩法,市场热度持续高涨
- STM32F103ZET6【标准库函数开发】----库函数介绍
- K210 learning notes (II) serial communication between k210 and stm32
- bashdb下载安装
- Error: cannot find or load main class
- How much inventory recording does the intelligent system of external call system of okcc call center need?
- Single chip microcomputer nixie tube stopwatch
- Judgment on heap (25 points) two insertion methods
- Valgrind et kcachegrind utilisent l'analyse d'exécution
- 请问中衍期货安全靠谱吗?
猜你喜欢

valgrind和kcachegrind使用運行分析

資源打包關系依賴樹

MySQL小练习(仅适合初学者,非初学者勿进)

经典题目刷一刷

2022-04-22 openebs cloud native storage

Resource packaging dependency tree

2021 Li Hongyi's adaptive learning rate of machine learning

L2-3 romantic silhouette (25 points)

请提前布局 Star Trek突破链游全新玩法,市场热度持续高涨

Notes on 30 steps of introduction to Internet of things of yangtao electronics STM32 III. Explanation of new cubeide project and setting
随机推荐
Brief steps to build a website / application using flash and H5
L2-023 graph coloring problem (25 points) (graph traversal)
L2-022 重排链表 (25 分)(map+结构体模拟)
完全二叉搜索树 (30 分)
Summary of solid problems
ESP32程序下载失败,提示超时
Illegal character in scheme name at index 0:
The crawler returns null when parsing with XPath. The reason why the crawler cannot get the corresponding element and the solution
Kubernetes如何使用harbor拉去私有镜像
Automatic differentiation and higher order derivative in deep learning framework
Notes on 30 steps of introduction to the Internet of things of yangtao electronics STM32 III. cubemx graphical programming and setting the IO port on the development board
Go语言自学系列 | golang嵌套结构体
LaTeX数学公式
dataBinding中使用include
MySQL查询两张表属性值非重复的数据
rembg 分割mask
Go language self-study series | initialization of golang structure
Download and install bashdb
Star Trek强势来袭 开启元宇宙虚拟与现实的梦幻联动
Wechat: get the owner of a single tag



