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

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

合肥工业大学—SQL Server数据库实验七:数据查询

發(fā)布時間:2023/11/28 生活经验 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 合肥工业大学—SQL Server数据库实验七:数据查询 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

數(shù)據(jù)查詢

  • 1. 單表查詢
  • 2. 多表連接查詢


1. 單表查詢

1. 查詢?nèi)w學(xué)生的信息;

-- 查詢?nèi)w學(xué)生的信息
select * from student

2. 根據(jù)專業(yè)編號(21)查詢學(xué)生的學(xué)號、性別和年齡;

-- 根據(jù)專業(yè)編號查詢學(xué)生的學(xué)號、性別和年齡
select st_id '學(xué)號',st_sex '性別',datediff(year,st_born,getdate()) '年齡' from student where tc_mj = 21 

3. 查詢未設(shè)定先修課的所有課程的信息;

-- 查詢未設(shè)定先修課的所有課程的信息
select * from course where cs_prerequisite is null

4. 查詢選修了‘100’號課程,且成績達(dá)到80分的學(xué)號;

-- 查詢選修了‘100’號課程,且成績達(dá)到80分的學(xué)號;
select sc_id from select_course where sc_num = 100 and sc_grade > 80


2. 多表連接查詢

1. 查詢“計(jì)算機(jī)與信息系”(系號1)全體學(xué)生的學(xué)號、姓名、專業(yè)名稱;

-- 查詢“計(jì)算機(jī)與信息系”(系號1)全體學(xué)生的學(xué)號、姓名、專業(yè)名稱
select st_id,st_name,mj_name from student,major where student.tc_mj = major.mj_id and mj_dpt = '1'

2. 查詢非“人工智能”(專業(yè)號21)專業(yè),年齡小于20的學(xué)生信息;

-- 查詢非“人工智能”(專業(yè)號21)專業(yè),年齡小于20的學(xué)生信息
select * from student where tc_mj <> 23 and datediff(year,st_born,getdate())<20

3. 查詢先修課是“計(jì)算機(jī)基礎(chǔ)”(課程號94)的所有課程的信息;

-- 查詢先修課是“計(jì)算機(jī)基礎(chǔ)”(課程號94)的所有課程的信息
select * from course where cs_prerequisite = 94

4. 查詢至少選修了‘100’和‘96’課程的學(xué)生學(xué)號

-- 查詢至少選修了‘100’和‘96’課程的學(xué)生學(xué)號
select sc_id from select_course sc1 where sc_num = 100 and exists (select * from select_course sc2 where sc2.sc_num = 96 and sc1.sc_id = sc2.sc_id) 

5. 查詢未選修“JAVA技術(shù)”(課程號100)課程的學(xué)生學(xué)號、姓名、性別和專業(yè)號

-- 查詢未選修“JAVA技術(shù)”課程的學(xué)生學(xué)號、姓名、性別和專業(yè)號
select distinct sc_id '學(xué)號',st_name '姓名',st_sex '性別',tc_mj '專業(yè)號' from select_course,student where sc_id = st_id and sc_id not in(select sc_id from select_course where sc_num = 100)

6. 查詢未選修任何課程的學(xué)生學(xué)號和姓名

-- 查詢未選修任何課程的學(xué)生學(xué)號和姓名
select sc_id,st_id from select_course,student where sc_id = st_id and sc_id not in (select sc_id from select_course where sc_num is not null)

7. 查詢未被學(xué)生選修的課程號、課程名、先修課

-- 查詢未被學(xué)生選修的課程號、課程名、先修課
select cs_id,cs_name,cs_prerequisite from course,select_course where sc_id not in (select distinct sc_id from select_course)

8. 用派生關(guān)系查詢平均成績達(dá)到90分的學(xué)生學(xué)號、姓名和平均成績

-- 用派生關(guān)系查詢平均成績達(dá)到90分的學(xué)生學(xué)號、姓名和平均成績
select st_id '學(xué)號',st_name '姓名',avg_grade '平均成績' from student,(select sc_id,avg(sc_grade) as avg_grade from select_course group by sc_id) as sc_avg where avg_grade>90 and sc_avg.sc_id = student.st_id

9. 查詢學(xué)生的學(xué)號,只要先修課是“90”的課程他們都選修了

-- 查詢學(xué)生的學(xué)號,只要先修課是“90”的課程他們都選修了
-- 查詢不存在先選課為90的課程沒有選修的學(xué)生學(xué)號
select sc_id 
from 
select_course sc1 
where not exists (select * from course where cs_prerequisite = 90 and not exists (select * from select_course sc2 where sc2.sc_num = course.cs_id and sc2.sc_id = sc1.sc_id))

10. 查詢未參加課程“100”考試的學(xué)生名單(學(xué)號、姓名、專業(yè)號)

-- 查詢未參加課程“100”考試的學(xué)生名單(學(xué)號、姓名、專業(yè)號)
select distinct sc_id,st_name,tc_mj from select_course,student where sc_id = st_id and sc_id not in (select sc_id from select_course where sc_num = 100);

總結(jié)

以上是生活随笔為你收集整理的合肥工业大学—SQL Server数据库实验七:数据查询的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。