MySql实验嵌套查询_数据库实验:SQL嵌套查询
自测题:
1、查询哪些课程没有人选修列出课程号和课程名;
[code]select cno,cname
from course
where cno not in(
select distinct cno
from sc)[/code]
2、用子查询实现如下查询:
(1)查询选修了1号课程的学生姓名和所在系;
[code]select sname,sno
from student
where sno in(
select sno
from sc
where cno=1)[/code]
(2)查询“数据库”成绩在80分以上的学生的学号和姓名;
[code]Select sno,sname
From student
Where sno in(
select sno
from course,sc
where course.cno=sc.cno and course.cname='数据库' and grade>=80)[/code](3)查询计算机系最高成绩。
[code]select top 1 grade
from student,sc
where student.sno=sc.sno and sdept='CS'
order by grade desc[/code]
3、查询同时选修了1号和2号课程的学生学号
[code]select sno
from sc
where cno=1 and sno in(
select sno
from sc
where cno=2)[/code]
4、查询选修了“离散数学”的学生姓名(连接查询)
[code]select sname
from student
where sno in(
select sno
from course,sc
where course.cno=sc.cno and course.cname='离散数学')[/code]
5、查询选修课程名为“数据库”的学生姓名(子查询)
[code]select sname
from student
where sno in(
select sno
from course,sc
where course.cno=sc.cno and course.cname='数据库')[/code]
6、查询与张天和张琪在同一个系的学生
[code]select *
from student
where sdept in(
select sdept
from student
where sname='张天' or sname='张琪')[/code]
查询与张天或张琪不在同一个系的学生
[code]select *
from student
where sdept not in(
select sdept
from student
where sname='张天' or sname='张琪')[/code]
7、查询比信息系所有学生年龄大的学生姓名
[code]select sname
from student s1
where s1.sage>all(
select sage
from student s2
where s2.sdept='CS')[/code]
8、查询比张天平均成绩高的学生姓名
[code]select sname
from student
where student.sno in(
select sno
from sc
group by sno
having avg(grade) >(
select avg(grade) as avg_grade2
from sc sc2,student
where student.sno=sc2.sno and sname='刘晨'
group by sc2.sno)
)[/code]9、查询比学号为200215121学生年龄大的学生
[code]select *
from student s1
where s1.sage>(
select sage
from student s2
where s2.sno='200215121')[/code]
10、查询各系总分最高的学生学号
[code]Select sdept,student.sno
from student,sc
where student.sno=sc.sno
group by sdept,student.sno
having sum(grade)>=all(
select sum(grade)
from student,sc
where student.sno=sc.sno and sdept=student.sdept
group by student.sno)[/code]
11、查询选修了以6号课程为先行课的所有课程的学生学号。
[code]select distinct sno
from sc
where sc.cno in(
select cno
from course
where cpno=6)[/code]
MySql实验嵌套查询_数据库实验:SQL嵌套查询相关推荐
- mysql实验三单表和多表查询_数据库实验三(单表查询)
实验三: select sno,sname from student;//(1)查询全体学生的学号和姓名 select * from student;//(2)查询全体学生的详细记录 select s ...
- mysql实验学生表_数据库实验(学生信息表)
数据库实验(学生信息表) 实验一 创建数据库以及学生信息表.课程信息表.选课表 create Table student (Sno char(9) primary key, Sname char(20 ...
- MySQL删除空值语句_数据库语句sql 删除空记录
最简单删除SQL Server中所有数据的方法 原文:最简单删除SQL Server中所有数据的方法 最简单删除SQL Server中所有数据的方法 编写人:CC阿爸 2014-3-14 其实 ...
- mysql select 所有表_怎样用SQL语句查询一个数据库中的所有表
展开全部 查询32313133353236313431303231363533e59b9ee7ad9431333431356639一个数据库中的所有表sql语句是show tables: 显示所有数据 ...
- mysql实验总结_数据库实验的心得体会.docx
数据库实验的心得体会 数据库实验心得体会 篇一:数据库实训总结 SQL Server 数据库管理课实训报告 这个星期是我们SQL Server 数据库管理课的实训,经过一个星期的实训,让我将书本上的理 ...
- oracle 查询当年数据_查询ORACLE数据库TOP SQL使用情况
使用BOOST和ORACLE::OCCI查询ORACLE数据库TOP SQL使用情况 /topsql.h#ifndef TOPSQL_H#define TOPSQL_H#include#include ...
- db2 删除存储过程_数据库教程-SQL Server存储过程使用及异常处理
SQL Server存储过程 存储过程(Procedure)是数据库重要对象之一,也是数据库学习的重点之一.本文,我们以SQL Server为例对存储过程的概念.定义.调用.删除及存储过程调用异常等通 ...
- mysql数据库实验查询_数据库表的查询操作(实验二)
[实验目的]:了解SQL语言的使用,进一步理解关系运算,巩固数据库的基础知识. [实验要求]:掌握利用Select语句进行各种查询操作:单表查询.多表连接及查询.嵌套查询.集合查询等. [实验内容] ...
- MySQL实验四数据库的查询_MySQL数据库实验四:嵌套查询
实验四 嵌套查询 一.实验目的 掌握SELECT语句的嵌套使用,实现表的复杂查询,进一步理解SELECT语句的高级使用方法. 二.实验环境 三.实验示例 1. 查询与"刘 ...
最新文章
- Java基于对象基础 基于对象和面向对象的区别(转)
- 微信小程序图片轮转播放
- mysql 临时表 汉字_转MySQL临时表的简单用法
- socket connec连接超时处理
- php服务器 下载,php实现从服务器下载文件
- 【渝粤教育】电大中专电商运营实操 (23)作业 题库
- Leetcode--120. 三角形最小路径和
- SpringBoot部署项目到Linux上传文件路径问题
- 【转载】网站从百度云转入阿里云服务器
- python并行计算进程池通信_Python使用进程池管理进程和进程间通信
- 计算机秘密程序 听课反思,《编制计算机程序解决问题》的教学反思
- centos6.8 开启透传
- html标题居中加背景色,如何设置CSS背景宽度后让文字居中?
- gitbook:epub电子书制作教程
- 工商银行总行营业厅管理软件设置视频教程
- 菜鸡小南橙的成长之路————bugkuCTF解题记录(一)
- 潜在因子模型_如何使用潜在因子模型在图形数据库中构建推荐系统
- 大一计算机论文_大一计算机论文大纲模板范文 大一计算机论文提纲怎样写
- php什么框架,php快速开发用什么框架
- 教科书式RSA方案面临的攻击及防御措施