04-27 Mysql exam 55 points short answer record

The second question sheet

#New student table
drop table if exists setudent;
create table setudent(
    sno int(10) not null primary key comment 'student number',
    sname varchar(20) not null comment 'name',
    ssex varchar(10) not null comment ' Gender'
); #Add
data to the student table
insert into setudent values(1,'Jiang Zhenguo','male'),(2,'Zhao Shuwen','male'),(3,'Rui Sihan','female'), (4,'Yu Haoran','male'); #Create a

new curriculum
drop table if exists coures;
create table coures(
    cnoc int(10) not null primary key comment 'Course ID',
    name varchar(30) not null comment 'Course name'
); #Add
data to the curriculum
insert into coures values(1,'java'),(2,'oracle'),(3,'js'),(4,'jquery');#Create a
new course selection table
drop table if exists selclass;
create table selclass(
    selno int(10) not null primary key auto_increment comment 'Course ID',
    sno int(10) not null comment 'Student ID',
    cno int(10) not null comment 'Course ID',
    count int(10) not null comment 'Grade'
); #Add
data to the course selection table
insert into selclass values(1,1,1,88),(2,1,2,77),(3,2,1,78),(4,2, 2,91),(5,3,1,55),(6,3,2,65),(7,3,3,75),(10,4,3,74),(9,4, 4,64);

first question sheet

drop table if exists student;
create table student(
    sno int not null primary key comment'student ID',
    sname varchar(20) not null comment'name',
    ssex varchar(20) not null comment'gender',
    splace varchar(20 ) not null comment'Hometown',
    syxid varchar(20) not null comment'Department ID'
);
drop table if exists yxinfo;
create table yxinfo(
    yxid int not null primary key comment'Department ID',
    yxname varchar(20 ) not null comment'Department name',
    yxplace varchar(20) not null comment'Address',
    yxphone varchar(20) not null comment'Contact phone number'
);
insert into student values
    ​​('1','Wen Huiqing',' Female','Jiangsu','1'),
    ('2','Zhao Hetang','Male','Chongqing City','2'),
    ('3','Zhao Xiuping','male','Hebei','1'),
    ('4','Qin Yi','male','Fujian','3'),
    ('5' ,'He Lingquan','Female','Fujian','3'),
    ('6','Zhou Hailong','Male','Shandong','1');
insert into yxinfo values
    ​​('1', 'Computer Department','Research Building 608','0533-2168068'),
    ('2','Mathematics Department','Administrative Building 203','0533-2157068'),
    ('3','Physics Department' ,'Research Building 607','0533-3153606');
The first question
1. Find out all the student information of 'Computer Department'
select * from student where syxid =(select yxid from yxinfo where yxname = 'Computer Department');
2.
Find out the information of the department where 'Zhao Hetang' is located select * from yxinfo where yxid = (select syxid from student where sname = 'Zhao Hetang');
3. Find out the name of the department working in the 'Administration Building';
select yxname from yxinfo where yxplace like 'Administrative Building%';
4. Find out how many boys and girls there are
select ssex,count(*) from student group by ssex;
5. Find out the department with the largest number of people
select * from yxinfo where yxid =(select syxid from student group by syxid order by count(*) desc limit 1);
6. Find out the number of male and female students in the department with the largest number of students
select ssex,count(*) from student where syxid = (select syxid from student group by syxid order by count(*) desc limit 1) group by ssex;
7. Find out all the people who have the same origin as 'Qin Yi'
select sname from student where splace = (select splace from student where sname = 'Qin Yi');
8. Find out the information of the faculties and departments studied by the person in 'Hebei'
select * from yxinfo where yxid = (select syxid from student where splace = 'Hebei');
9. Find out the information related to 'Fujian' Female' All student information in the same department;
select * from student where syxid = (select syxid from student where splace = 'Fujian' and ssex = 'female');
Question
2 1. Query the names of students who have taken 'oracle'

select sname from setudent where sno in (select sno from selclass where cno
in ( select cnoc from coures where name = 'oracle')); selclass where sno in (select sno from setudent where sname = 'Jiang Zhenguo'));
3. Query the student number and name of students who only took one course;
select sno,sname from setudent where setudent.sno in (select selclass.sno from selclass group by selclass.sno having count(*) = 1);
4. Query the information of students who have taken at least 3 courses
select * from setudent where setudent.sno in (select selclass.sno from selclass group by selclass.sno having count(*) >= 3);
5. Query students who have taken all courses
select * from setudent where setudent.sno in (select selclass.sno from selclass group by selclass.sno having count(*) =(select count(* ) from coures));
6. To query the number of students in elective courses
select cno,count(*) from selclass group by selclass.cno;
7. To query the student information of at least one of the courses taken
by Jiang Zhenguo select setudent.sno,sname,ssex from setudent join selclass on setudent.sno = selclass.sno where selclass.cno in (select selclass.cno from selclass join setudent on setudent.sno = selclass.sno where sname = 'Jiang Zhenguo');
8. Query two or more Average score of failing students
select sname,avg(count) from selclass a join setudent on setudent.sno = a.sno ​​where a.sno ​​= (select b.sno from selclass b where count < 60 group by b.sno having count (*) >=2) group by a.sno;

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324998350&siteId=291194637