SQL查询语句|PTA题目集

R10-16 查询教授多门课程的教师编号及教授的课程门数

作者 马丰媛

单位 大连东软信息学院

题目描述:查询教授多门课程的教师编号及教授的课程门数。

提示:请使用SELECT语句作答。

表结构:

SC表结构:

create table  SC( 
  scid  int auto_increment  primary key,
  sno char(8)   references Student(sno),
  cno char(10)  references Course(cno),
  tno char(15)  references Teacher(tno),
  grade int check(grade>=0 and grade<=100),
  gpoint  decimal(2,1), 
  memo  text(100) 
  );

表样例

请在这里给出上述表结构对应的表样例。例如

SC表:

image.png

输出样例:

请在这里给出输出样例。例如:

image.png

 

select tno,count(distinct cno) as 门数
from SC
group by tno
having count(distinct cno)>=2;

 R10-17 查询选修了3门及3门以上课程的学生学号、平均成绩和修课门数,并用中文显示列名

 

作者 马丰媛

单位 大连东软信息学院

题目描述:查询选修了3门及3门以上课程的学生学号、平均成绩和修课门数,并用中文显示列名。

提示:请使用SELECT语句作答。

表结构:

SC表结构的SQL语句:

create table  SC( 
  scid  int auto_increment  primary key,
  sno char(8)   references Student(sno),
  cno char(10)  references Course(cno),
  tno char(15)  references Teacher(tno),
  grade int check(grade>=0 and grade<=100),
  gpoint  decimal(2,1), 
  memo  text(100) 
  );

表样例

请在这里给出上述表结构对应的表样例。例如

SC表:

image.png

输出样例:

请在这里给出输出样例。例如:

image.png

select sno as 学号,avg(grade) as 平均成绩,count(distinct cno) as 修课门数
from SC
group by sno
having count(distinct cno)>=3;

 

R10-18 计算21012101号学生的修课总成绩

 

 

作者 马丰媛

单位 大连东软信息学院

题目描述:计算21012101号学生的修课总成绩。

提示:请使用SELECT语句作答。

表结构:

SC表结构的SQL语句:

create table  SC( 
  scid  int auto_increment  primary key,
  sno char(8)   references Student(sno),
  cno char(10)  references Course(cno),
  tno char(15)  references Teacher(tno),
  grade int check(grade>=0 and grade<=100),
  gpoint  decimal(2,1), 
  memo  text(100) 
  );

表样例

请在这里给出上述表结构对应的表样例。例如

SC表:

image.png

输出样例:

请在这里给出输出样例。例如:

image.png

 

select sno,sum(grade) as 总成绩
from SC
where sno=21012101;

 

R10-19 计算C01号课程学生的考试平均成绩

 

作者 马丰媛

单位 大连东软信息学院

题目描述:计算C01号课程学生的考试平均成绩。

提示:请使用SELECT语句作答。

表结构:

SC表结构的SQL语句:

create table  SC( 
  scid  int auto_increment  primary key,
  sno char(8)   references Student(sno),
  cno char(10)  references Course(cno),
  tno char(15)  references Teacher(tno),
  grade int check(grade>=0 and grade<=100),
  gpoint  decimal(2,1), 
  memo  text(100) 
  );

表样例

SC表:

image.png

输出样例:

请在这里给出输出样例。例如:

image.png

 

select avg(grade) as 平均成绩
from SC
where cno='c01';

 

R10-20 检索部门名为“SLAES”的所有员工工号和姓名

 

作者 蒋维

单位 浙江树人学院

检索部门名为“SLAES”的所有员工工号和姓名

提示:请使用SELECT语句作答。

表结构:

请在这里写定义表结构的SQL语句。例如:

CREATE TABLE `dept` (
  `deptno` decimal(2,0) NOT NULL,
  `dname` varchar(14) DEFAULT NULL,
  `loc` varchar(13) DEFAULT NULL,
  PRIMARY KEY (`deptno`)
) ;

CREATE TABLE `emp` (
  `empno` decimal(4,0) NOT NULL,
  `ename` varchar(10) DEFAULT NULL,
  `job` varchar(9) DEFAULT NULL,
  `mgr` decimal(4,0) DEFAULT NULL,
  `hiredate` date DEFAULT NULL,
  `sal` decimal(7,2) DEFAULT NULL,
  `comm` decimal(7,2) DEFAULT NULL,
  `deptno` decimal(2,0) DEFAULT NULL,
  PRIMARY KEY (`empno`)
) ;

CREATE TABLE `salgrade` (
  `grade` decimal(10,0) NOT NULL,
  `losal` decimal(10,0) DEFAULT NULL,
  `hisal` decimal(10,0) DEFAULT NULL,
  PRIMARY KEY (`grade`)
);

表样例

emp表:

image.png

dept表:

image.png

输出样例:

image.png

 

select empno,ename
from emp,dept
where emp.deptno=dept.deptno
    and dname='SALES';

  • 7
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值