日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

MySql实验嵌套查询_数据库实验:SQL嵌套查询

發布時間:2023/12/20 数据库 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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嵌套查询的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。