1. 程式人生 > >04-27 Mysql 考試 55 分 簡答題記錄

04-27 Mysql 考試 55 分 簡答題記錄

rom bsp col key jquery 計算機 har 聯系電話 not

第二題表

#新建學生表
drop table if exists setudent;
create table setudent(
sno int(10) not null primary key comment ‘學號‘,
sname varchar(20) not null comment ‘姓名‘,
ssex varchar(10) not null comment ‘性別‘
);
#給學生表添加數據
insert into setudent values(1,‘姜振國‘,‘男‘),(2,‘趙書文‘,‘男‘),(3,‘芮思涵‘,‘女‘),(4,‘余浩然‘,‘男‘);

#新建課程表
drop table if exists coures;


create table coures(
cnoc int(10) not null primary key comment ‘課程ID‘,
name varchar(30) not null comment ‘課程名稱‘
);
#給課程表添加數據
insert into coures values(1,‘java‘),(2,‘oracle‘),(3,‘js‘),(4,‘jquery‘);
#新建選課表
drop table if exists selclass;
create table selclass(
selno int(10) not null primary key auto_increment comment ‘選課ID‘,

sno int(10) not null comment ‘學生ID‘,
cno int(10) not null comment ‘課程ID‘,
count int(10) not null comment ‘成績‘
);
#給選課表添加數據
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);

第一題表

drop table if exists student;
create table student(


sno int not null primary key comment‘學生ID‘,
sname varchar(20) not null comment‘姓名‘,
ssex varchar(20) not null comment‘性別‘,
splace varchar(20) not null comment‘籍貫‘,
syxid varchar(20) not null comment‘院系ID‘
);
drop table if exists yxinfo;
create table yxinfo(
yxid int not null primary key comment‘院系ID‘,
yxname varchar(20) not null comment‘院系名稱‘,
yxplace varchar(20) not null comment‘地址‘,
yxphone varchar(20) not null comment‘聯系電話‘
);
insert into student values
(‘1‘,‘溫惠青‘,‘女‘,‘江蘇‘,‘1‘),
(‘2‘,‘趙和堂‘,‘男‘,‘重慶市‘,‘2‘),
(‘3‘,‘趙修平‘,‘男‘,‘河北‘,‘1‘),
(‘4‘,‘秦奕‘,‘男‘,‘福建‘,‘3‘),
(‘5‘,‘何靈泉‘,‘女‘,‘福建‘,‘3‘),
(‘6‘,‘周海龍‘,‘男‘,‘山東‘,‘1‘);
insert into yxinfo values
(‘1‘,‘計算機系‘,‘科研樓608‘,‘0533-2168068‘),
(‘2‘,‘數學系‘,‘行政樓203‘,‘0533-2157068‘),
(‘3‘,‘物理系‘,‘科研樓607‘,‘0533-3153606‘);
第一題
1.查出‘計算機系’的所有學生信息
select * from student where syxid =(select yxid from yxinfo where yxname = ‘計算機系‘);
2.查出‘趙和堂’所在的院系信息
select * from yxinfo where yxid = (select syxid from student where sname = ‘趙和堂‘);
3.查出在‘行政樓’辦公的院系名稱;
select yxname from yxinfo where yxplace like ‘行政樓%‘;
4.查出男生女生各多少人
select ssex,count(*) from student group by ssex;
5.查出人數最多的院系
select * from yxinfo where yxid =(select syxid from student group by syxid order by count(*) desc limit 1);
6.查出人數最多的院系的男女生各多少人
select ssex,count(*) from student where syxid = (select syxid from student group by syxid order by count(*) desc limit 1) group by ssex;
7.查出跟‘秦奕‘同籍貫的所有人
select sname from student where splace = (select splace from student where sname = ‘秦奕‘);
8.查出‘河北‘人就讀的院系信息
select * from yxinfo where yxid = (select syxid from student where splace = ‘河北‘);
9.查出跟‘福建女生‘ 同院系的所有學生信息;
select * from student where syxid = (select syxid from student where splace = ‘福建‘ and ssex = ‘女‘);
第二題
1.查詢選修了‘oracle‘的學生姓名
select sname from setudent where sno in(select sno from selclass where cno in (select cnoc from coures where name = ‘oracle‘));
2.查詢 姜振國 同學選修了的課程名稱
select name from coures where cnoc in (select cno from selclass where sno in (select sno from setudent where sname = ‘姜振國‘));
3.查詢只選修了一門課的學生學號和姓名;
select sno,sname from setudent where setudent.sno in (select selclass.sno from selclass group by selclass.sno having count(*) = 1);
4.查詢選修了至少3門課程的學生信息
select * from setudent where setudent.sno in (select selclass.sno from selclass group by selclass.sno having count(*) >= 3);
5.查詢選修了所有課程的學生
select * from setudent where setudent.sno in (select selclass.sno from selclass group by selclass.sno having count(*) =(select count(*) from coures));
6.查詢選修課程的學生人數
select cno,count(*) from selclass group by selclass.cno;
7.查詢所學課程至少有一門跟姜振國所學課程相同的學生信息
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 = ‘姜振國‘);
8.查詢兩門及兩門以上不及格同學的平均分
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;

04-27 Mysql 考試 55 分 簡答題記錄