SQL笔试题:下面是学生表(student)的结构说明

SQL笔试题:下面是学生表(student)的结构说明

字段名称

字段解释

字段类型

字段长度

约束

s_id

学号

字符

10

PK

s_name

学生姓名

字符

50

Not null

s_age

学生年龄

数值

3

Not null

s-sex

学生性别

字符(男:1女:0)

1

Not null

下面是教师表(Teacher )的结构说明

字段名称

字段解释

字段类型

字段长度

约束

t_id

教师编号

字符

10

PK

t_name

教师名字

字符

50

Not null

下面是课程表(Course)的结构说明

字段名称

字段解释

字段类型

字段长度

约束

c_id

课程编号

字符

10

PK

c_name

课程名字

字符

50

Not null

t_id

教师编号

字符

10

Not null

下面是成绩表(SC)的结构说明

字段名称

字段解释

字段类型

字段长度

约束

s_id

学号

字符

10

PK

c_id

课程编号

字符

10

Not null

score

成绩

数值

3

Not null

1、查询“001”课程比“002”课程成绩高的所有学生的学号;

select a.s_id from (select s_id,score from SC where C_ID='001') a,(select s_id,score

from SC where C_ID='002') b
where a.score>b.score and a.s_id=b.s_id;

2、查询平均成绩大于60分的同学的学号和平均成绩;

select S_ID,avg(score)
from sc
group by S_ID having avg(score) >60;

3、查询所有同学的学号、姓名、选课数、总成绩;

select Student.S_ID,Student.Sname,count(SC.C_ID),sum(score)
from Student left Outer join SC on Student.S_ID=SC.S_ID
group by Student.S_ID,Sname

4、查询姓“李”的老师的个数;

select count(distinct(Tname))
from Teacher
where Tname like '李%';

5、查询没学过“叶平”老师课的同学的学号、姓名;

select Student.S_ID,Student.Sname
from Student
where S_ID not in (select distinct( SC.S_ID) from SC,Course,Teacher where SC.C_ID=Course.C_ID and Teacher.T#=Course.T# and Teacher.Tname='叶平');

6、查询学过“001”并且也学过编号“002”课程的同学的学号、姓名;

elect Student.S_ID,Student.Sname from Student,SC where Student.S_ID=SC.S_ID and SC.C_ID='001'and exists( Select * from SC as SC_2 where SC_2.S_ID=SC.S_ID and SC_2.C_ID='002');

7、查询学过“叶平”老师所教的所有课的同学的学号、姓名;

select S_ID,Sname
from Student
where S_ID in (select S_ID from SC ,Course ,Teacher where SC.C_ID=Course.C_ID and Teacher.T#=Course.T# and Teacher.Tname='叶平' group by S_ID having count(SC.C_ID)=(select count(C_ID) from Course,Teacher where Teacher.T#=Course.T# and Tname='叶平'));

8、查询课程编号“002”的成绩比课程编号“001”课程低的所有同学的学号、姓名;

Select S_ID,Sname from (select Student.S_ID,Student.Sname,score ,(select score from SC SC_2 where SC_2.S_ID=Student.S_ID and SC_2.C_ID='002') score2
from Student,SC where Student.S_ID=SC.S_ID and C_ID='001') S_2 where score2 < score;

9、查询所有课程成绩小于60分的同学的学号、姓名;

select S_ID,Sname
from Student
where S_ID not in (select S.S_ID from Student AS S,SC where S.S_ID=SC.S_ID and score>60);

10、查询没有学全所有课的同学的学号、姓名;

select Student.S_ID,Student.Sname
from Student,SC
where Student.S_ID=SC.S_ID group by Student.S_ID,Student.Sname having count(C_ID) <(select count(C_ID) from Course);

11、查询至少有一门课与学号为“1001”的同学所学相同的同学的学号和姓名;

select distinct S_ID,Sname from Student,SC where Student.S_ID=SC.S_ID and SC.C_ID in (select C_ID from SC where S_ID='1001');

12、查询至少学过学号为“001”同学所有一门课的其他同学学号和姓名;

select distinct SC.S_ID,Sname
from Student,SC
where Student.S_ID=SC.S_ID and C_ID in (select C_ID from SC where S_ID='001');

SQL笔试题:下面是学生表(student)的结构说明的更多相关文章

  1. sql-hive笔试题整理 1 (学生表-成绩表-课程表-教师表)

    题记:一直在写各种sql查询语句,最长的有一百多行,自信什么需求都可以接,可......,想了想,可能一直在固定的场景下写,平时也是以满足实际需求为目的,竟不知道应试的题都是怎么出的,又应该怎么做.遂 ...

  2. SQLServer 常见SQL笔试题之语句操作题详解

    SqlServer 常见SQL笔试题之语句操作题详解 by:授客 QQ:1033553122 测试数据库 CREATE DATABASE handWriting ON PRIMARY ( name = ...

  3. [SQL]数据分析SQL笔试题

    SQL笔试题 1.请简单写出left join和join的用法区别(可举例说明): 2.求出订单表(order表)中每个客户(custid)的最近一次购买日期(要求:按custid降序排列,trans ...

  4. 【笔试必备】常见sql笔试题(30题)

    sql是测试从业者必备的技能之一,基本上也是笔试必考内容. 所以,不要让sql拖了后腿,有些测友一遇到多表关联查询就犯晕,甚至连单表的执行顺序都没搞懂,下面简单介绍下,顺便给一些题供大家练习. 单表执 ...

  5. 必会SQL笔试题

    ()表名:购物信息 购物人 商品名称 数量 A 甲 B 乙 C 丙 A 丁 B 丙 …… 给出所有购入商品为两种或两种以上的购物人记录 答:); ()表名:成绩表 姓名 课程 分数 张三 语文 张三 ...

  6. SQL Server 基础之《学生表-教师表-课程表-选课表》(二)

    表结构 --学生表tblStudent(编号StuId.姓名StuName.年龄StuAge.性别StuSex) --课程表tblCourse(课程编号CourseId.课程名称CourseName. ...

  7. sql笔试题

    笔试题1: 1.select * from tablex where name = "张*" order by age  默认升序      select * from table ...

  8. SQL Server 基础之《学生表-教师表-课程表-选课表》

    一.数据库表结构及数据 建表 CREATE TABLE Student ( S# INT, Sname ), Sage INT, Ssex ) ) CREATE TABLE Course ( C# I ...

  9. SQL Server 基础之《学生表-教师表-课程表-选课表》(一)

    数据库表结构及数据 建表 CREATE TABLE Student ( S# INT, Sname ), Sage INT, Ssex ) ) CREATE TABLE Course ( C# INT ...

随机推荐

  1. bzoj1002 轮状病毒 暴力打标找规律/基尔霍夫矩阵+高斯消元

    基本思路: 1.先观察规律,写写画画未果 2.写程序暴力打表找规律,找出规律 1-15的答案:1    5    16    45    121 320 841     2205   5776 151 ...

  2. python处理文件某行的固定位置

    1.打开文件 2.按行循环 3.处理固定行 with open('file/Aa.txt') as f: for line in f: print(line[2:12]) 可以这样处理的原因是,lin ...

  3. exists 的简单介绍

    准备数据: CREATE TABLE Books( BookID number, BookTitle VARCHAR2(20) NOT NULL, Copyright varchar2(20) ) I ...

  4. spring-boot整合Mybatis多数据源案例

    1.运行环境 开发工具:intellij idea JDK版本:1.8 项目管理工具:Maven 4.0.0 2.GITHUB地址 https://github.com/nbfujx/springBo ...

  5. 一、生成网络表--create Netlist

    Orcad Capture原理图篇 一.生成网络表--create Netlist 1.操作: .dsn文件--Tools--create Netlist 出现如下对话框--默认不进行更改--点击确定 ...

  6. 1-什么是 Prometheus

    什么是 Prometheus Prometheus 是由 SoundCloud 开源监控告警解决方案,从 2012 年开始编写代码,再到 2015 年 github 上开源以来,已经吸引了 9k+ 关 ...

  7. speike

    speike 题目描述 众所周知,Speike 狗是一条特别喜欢追着Tom 打的狗. 现在,Tom 又把Speike 惹生气了,现在Speike 需要跨越千山万水找Tom 报仇. Speike 所在的 ...

  8. 请教怎么查询ORACLE的历史操作记录!

    请问如何查询ORACLE的历史操作记录!!!!!我用的是linux oracle 11g r2,想查一下前几天的数据库的历史操作记录,例如对表的insert,delete,update等等的操作记录, ...

  9. C# JS 前后端互传数据

    ---恢复内容开始--- 后端: public void ProcessRequest(HttpContext context) { context.Response.ContentType = &q ...

  10. hive中not in优化

    比如:A,B两表,找到ID字段中,存在A表,但不存在B表的数据. A表共13w,去重后3w,B表共2W,且有索引 方法一 not in,易理解,效率低,时间:1.395s )