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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 综合教程 >内容正文

综合教程

SQL基础三(例子)

發布時間:2023/12/13 综合教程 28 生活家
生活随笔 收集整理的這篇文章主要介紹了 SQL基础三(例子) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

-----------聚合函數使用------------------------

--1、查詢student表中所有學生人數
select count(stuno) from student

--2、查詢stucou表中選課的人次
select count(*)as 選課人數 from stucou

--3、查詢stucou表中學生所選課程數量
select count(distinct couno) from stucou 

--4、查詢stucou表中選了001課程的人數
select count(*) from stucou where couno='001'

--5、查詢stucou表中第2志愿(willorder)選了001課程的人數
select count(*) from stucou where willorder='2' and couno='001'

--6、統計student2010表中籍貫與你相同(同一縣、區或市)的學生人數
select count(*) from student2010 where  jtdz like '%汕頭%'

--7、統計student2010表中與你同姓的學生人數
select * from student2010 where xm like '陳%'

--8、查詢qypt08class表班級最多的人數
select max(rs) from qypt08class

--9、查詢qypt08class表護理學院的班級最少人數
select min(rs) from qypt08class

---------分組統計(group by子句使用)--------------------


--1、統計student2010表中男、女生人數
select xb, count(xb) from student2010 group by xb

--2、統計stucou表中各門課程的選修人數
select * from stucou
select couno, count(*) from stucou group by couno

--3、統計stucou表中每個學生選修的課程數量
select * from stucou
select stuno,count(*) from stucou group by stuno

--4、統計student2010表中每個院系的學生人數
select * from student2010
select xymc,count(*) from student2010 group by xymc
--5、統計student2010表中每個班的學生人數,顯示yxmc,bj及對應的人數,并按人數由多到少排序
select * from student2010
select bjmc,xymc,count(*) as 人數 from student2010 group by bjmc,xymc order by 人數 desc
--6、統計student2010表中各民族學生人數,并按人數由少到多排序
select mz,count(*) from student2010 group by mz order by count(*)

--7、在student2010表分專業統計男、女生人數,按專業名稱排序
select zymc,xb,count(*) as 人數 from student2010 group by zymc,xb order by 人數 desc


-------------------對分組統計的結果進一步篩選(having子句使用)------------------------------

--1、查詢qypt08class表中各院系的人數,只顯示人數多于400的記錄
select * from qypt08class
select yx,sum(rs) from qypt08class group by yx having sum(rs)>400
--2、統計stucou表中各門課程的選修人數,只顯示人數少于30的記錄(顯示couno及對應的人數)
select * from stucou
select couno,count(*) from stucou group by couno having count(*)<30
--3、查詢student2010表中人數多于70人的班級的xymc、zymc、bjmc及rs(人數)
select * from student2010
select xymc,zymc,bjmc,count(*) from student2010 group by xymc,zymc,bjmc having count(*)>20
--------------------coupute子句使用----------------------



--1、在qypt08class中統計每個院系人數多于60的班級數,并顯示統計的明確









-------------------------將查詢保存為新表(into)--------------------


--1、查詢student2010表的xymc、zymc、bjmc、xh、xm五個字段內容,并將查詢結果保存到新表student2010A中

--查詢表student2010A的內容,檢驗上題操作結果



--2、統計student2010表中每班的人數(rs),并將結果保存到新表class2010,新表包含xymc、zymc、bjmc、rs四個字段

--查詢表class2010的內容,檢驗上題操作結果



--3、查詢表student2011中所有女生的信息,并將結果保存到表girl2011中



------使用嵌套子查詢完成1-7題----------

--1、在qypt08student表中查詢和“陳小梅”在同一班級的所有男同學的信息。
select * from qypt08student where bjmc in (select bjmc from qypt08student where xm='陳小梅') and xb='男'


--2、在qypt08student表中查詢和“黃巧”在同一院系的所有女同學的信息。
select * from qypt08student where yx=(select yx from qypt08student where xm='黃巧' ) and xb='女'

--3、在qypt08student表中查詢和“黃巧”在同一院系的所有陳姓女同學的信息。
select * from qypt08student where yx=(select yx from qypt08student where xm='黃巧' ) and xb='女' and xm like '陳%'
--4、查詢course表中最多人選修的課程信息(willnum最大)
select * from course where willnum in (select max(willnum) from course)

--5、查詢course表中最少人選修的課程信息(willnum最小)
select * from course where willnum=(select min(willnum) from course)

--6、查詢course表中選修人數大于平均選修數的課程信息
select * from course 
select  from course
--7、查詢course表中選修人數少于平均選修數的課程信息



------使用相關子查詢完成以下題目----------

--8、查詢所有有選修課的學生信息


--9、查詢沒有選修課程的學生信息


--10、查詢沒有人選修的課程信息


--11、查找選修了課程號為002的課程的學生信息


--12、查找20000001班沒有選修課程號為004的課程的學生信息


--13、查找選修了“智能建筑”課程的學生信息

------使用嵌套子查詢完成1-7題----------

--1、在qypt08student表中查詢和“陳小梅”在同一班級的所有男同學的信息。
select * from qypt08student where bjmc in (select bjmc from qypt08student where xm='陳小梅') and xb='男'


--2、在qypt08student表中查詢和“黃巧”在同一院系的所有女同學的信息。
select * from qypt08student where yx=(select yx from qypt08student where xm='黃巧' ) and xb='女'

--3、在qypt08student表中查詢和“黃巧”在同一院系的所有陳姓女同學的信息。
select * from qypt08student where yx=(select yx from qypt08student where xm='黃巧' ) and xb='女' and xm like '陳%'
--4、查詢course表中最多人選修的課程信息(willnum最大)
select * from course where willnum in (select max(willnum) from course)

--5、查詢course表中最少人選修的課程信息(willnum最小)
select * from course where willnum=(select min(willnum) from course)

--6、查詢course表中選修人數大于平均選修數的課程信息
select * from course 
select  from course
--7、查詢course表中選修人數少于平均選修數的課程信息



------使用相關子查詢完成以下題目----------

--8、查詢所有有選修課的學生信息


--9、查詢沒有選修課程的學生信息


--10、查詢沒有人選修的課程信息


--11、查找選修了課程號為002的課程的學生信息


--12、查找20000001班沒有選修課程號為004的課程的學生信息


--13、查找選修了“智能建筑”課程的學生信息


--1、在qypt08student表中查詢和“陳小梅”在同一班級的所有男同學的信息。
select * from qypt08student where bjmc in (select bjmc from qypt08student where xm='陳小梅') and xb='男'

--2、在qypt08student表中查詢和“黃巧”在同一院系的所有女同學的信息。

select * from qypt08student where yx=(select yx from qypt08student where xm='黃巧' ) and xb='女'
--3、在qypt08student表中查詢和“黃巧”在同一院系的所有陳姓女同學的信息。

select * from qypt08student where yx=(select yx from qypt08student where xm='黃巧' ) and xb='女' and xm like '陳%'
--4、查詢course表中最多人選修的課程信息(willnum最大)
select * from course where willnum in (select max(willnum) from course)

--5、查詢course表中最少人選修的課程信息(willnum最小)

select * from course where willnum=(select min(willnum) from course)

--6、查詢course表中選修人數大于平均選修數的課程信息
select avg(willnum) from course 
select * from course where willnum > (select avg(willnum) from course )

--7、查詢course表中選修人數少于平均選修數的課程信息
select * from course where willnum < (select avg(willnum) from course )


--8、查詢所有有選修課的學生信息
select * from student 
select * from course
select distinct stuno from stucou
select * from student where stuno in (select distinct stuno from stucou)
--9、查詢沒有選修課程的學生信息
select * from student where stuno not in  (select distinct stuno from stucou)

--10、查詢沒有人選修的課程信息
select * from course where willnum ='0'

--11、查找選修了課程號為002的課程的學生信息
select stuno from stucou where couno ='002'
select * from student where stuno in (select stuno from stucou where couno ='002')
--12、查找20000001班沒有選修課程號為004的課程的學生信息
 select * from class where classno ='20000001'
select * from course where couno not ='004'

--13、查找選修了“智能建筑”課程的學生信息


--14、查詢成績表中大于平均分的學生信息


--15、查詢已經選修了課程的學生信息



--視圖練習
--------------------------------------------------------------------------------
--第一題
--1、使用企業管理器創建視圖,要求數據表的來源為:department,class,student三個表
-----顯示學生每個學生所屬的院系名稱、班級名稱、學號及姓名,視圖保存為v_student

--2、在查詢分析器中查看視圖V_student的數據

--3、使用T-SQL語句創建一視圖,要求數據表的來源為:department,class,student三個表
-----顯示學生每個學生所屬的院系名稱、班級名稱、學號及姓名,視圖保存為v_student2

--4、在查詢分析器中查看視圖V_student2的數據

--第二題
--1、使用企業管理器創建視圖,數據表的來源為:class,student,course,stucou四個表
-----顯示每個學生的班級名稱、學號、選修的課程名稱,視圖保存為v_cou

--2、在查詢分析器中查看視圖V_cou的數據

--3、使用T-SQL語句創建一視圖,數據表的來源為:class,student,course,stucou四個表
-----顯示每個學生的班級名稱、學號、選修的課程名稱,視圖保存為v_cou2

--4、在查詢分析器中查看視圖V_cou2的數據

--第三題
--1、使用企業管理器創建視圖,數據表的來源為:department,class,student,course,stucou五個表
-----顯示每個學生所屬系部名稱,班級名稱、學號、姓名、選修的課程名稱,視圖保存為v_cou2A

--2、在查詢分析器中查看視圖V_cou2A的數據

--3、使用T-SQL語句創建一視圖,數據表的來源為:department,class,student,course,stucou五個表
-----顯示每個學生所屬系部名稱,班級名稱、學號、姓名、選修的課程名稱,視圖保存為v_cou2B

--4、在查詢分析器中查看視圖V_cou2B的數據

--第四題
--1、使用T-SQL語句創建一視圖,命名為V_stunocou。要求數據表的來源為stucou,course兩個表
-----顯示學生的學號及所選課程的名稱,并加密視圖的定義

--2、在查詢分析器中查看視圖V_stunocou的數據

--1、檢索student2010表中學制(XZ)為2年的學生信息

--2、檢索student2010表中班級名稱(BJMC)為“2010計算機網絡技術1班”的學生信息

--3、檢索student2010表中專業名稱(ZYMC)為“計算機網絡技術”的學生信息,按姓氏排序顯示

--4、檢索student2010表中專業名稱(ZYMC)為“計算機網絡技術”的學生的學號、姓名字段,字段名用中文顯示

--5、檢索stucou表中選修了004、009、010及015課程的記錄

--6、檢索student2010表中姓名最后一個字為“華”的女學生信息

--7、檢索student2010表中清新籍學生的信息

--8、顯示qypt08student表中的系部名稱(不重復顯示)

--9、顯示stucou表中所有willorder為1的記錄

--10、顯示stucou表中所有couno為003的記錄

--11、顯示stucou表中所有willorder為1且couno為003的記錄

--12、顯示stucou表中所有willorder為2到4的記錄

--13、顯示qypt08class表中備注(bz)不為空的記錄

--14、顯示qypt08student表中所有學號末位為1的記錄
select * from qypt08student where xh like '%1'
--15、顯示qypt08student表中每個班的學號為1號的記錄
select * from qypt08student where xh like '%01'
--16、顯示qypt08student表中所有姓‘張’的記錄
select * from qypt08student where xm like '張%'
--17、顯示qypt08student表中所有姓‘張’且姓名只包含兩個字的記錄
select * from qypt08student where xm like '張_'
--18、顯示qypt08student表中所有姓‘張’且姓名只包含兩個字的女性記錄
select * from qypt08student where xm like '張_' and xb like '女'
--19、顯示student表中Pwd的首末兩位均為7的記錄
select * from student where pwd like '7%7' 
--20、顯示qypt08student表中所有姓‘張’且姓名只包含三個字的記錄
select * from qypt08student where xm like '張%' and xm not like '張_'
--21、顯示qypt08student表中所有姓‘張’且姓名只包含三個字的男性記錄
select * from qypt08student where xm like '張%' and xm not like '張_' and xb like '男'
--22、顯示qypt08student表中所有姓張、李、劉的記錄
select * from qypt08student where xm like '[張,李,劉]%'
--23、檢索student2010表中身份證號碼(SFZH)的最后一位為數字的學生信息
select * from student2010 where sfzh like '%[0-9]'

總結

以上是生活随笔為你收集整理的SQL基础三(例子)的全部內容,希望文章能夠幫你解決所遇到的問題。

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

主站蜘蛛池模板: 西西人体www大胆高清 | 操穴影院 | 182tv午夜福利在线观看 | 免费看一级黄色大全 | 色屁屁www影院免费观看入口 | 国产拍拍拍拍拍拍拍拍拍拍拍拍拍 | 国产成人无码aa精品一区 | 天天想夜夜操 | 国产精品久久久久av | 黄色网址在线播放 | 亚洲av人人澡人人爽人人夜夜 | 天天干天 | 香蕉在线视频观看 | 午夜视频1000 | 四色成人av永久网址 | 国产又大又黑又粗免费视频 | 高清视频在线播放 | 在线观看一级片 | 人人妻人人澡人人爽国产一区 | 亚洲成人精品av | 欧美大黑b| 亚洲女人18毛片水真多 | 波多野结衣激情视频 | 国产一区在线免费 | 欧美日韩国产精品一区 | 精品久久久久久国产 | 理论黄色片 | 日本一道在线 | 97精品人妻一区二区三区 | 久草国产精品 | 久久久18禁一区二区三区精品 | 在线播放91 | 黄色小视频在线观看免费 | 日本国产高清 | 奇米精品一区二区三区在线观看一 | 天天看视频| 国产欧美精品久久 | 99在线无码精品入口 | 亚洲高清免费观看 | 69sese| 美女黄视频网站 | 亚洲熟妇一区二区三区 | 日本不卡三区 | 亚洲精品在线免费 | 国产一区二区三区四区五区在线 | 国产福利视频在线 | 美女又爽又黄 | 亚洲精品一区二区18漫画 | 四虎视频在线 | 最近2018年手机中文字幕版 | 国产尤物视频 | 欧美日韩一区二区三区电影 | 五月天婷婷伊人 | 国产精品第13页 | 欧美啊v| 免费观看h片 | 特黄一级大片 | 草1024榴社区成人 | 久久久无码人妻精品无码 | 亚洲欧美日韩在线看 | 日韩一区二区在线免费观看 | 美女色诱男人激情视频 | 麻豆激情网 | 体内精69xxxxx| 国产毛片一区二区三区 | 黄色片18 | 貂蝉被到爽流白浆在线观看 | 久久大香 | av无毛 | 天天宗合| 美女啪啪网 | 日韩色av | 美女脱了内裤喂我喝尿视频 | 国产成人免费av一区二区午夜 | 欧美色图首页 | 91久久在线观看 | 一区二区三区色 | 久久久全国免费视频 | 欧美日韩一二三区 | 亚欧精品在线观看 | 麻豆91在线播放 | 欧美色图在线观看 | 91视频久久久久 | 麻豆精品在线视频 | a猛片免费播放 | 最新av在线播放 | 国产又色又爽无遮挡免费 | 激情五月av | 视频一区二区视频 | 欧美日韩精品一区二区在线播放 | 久久久丁香 | 久久福利免费视频 | 日韩精品成人免费观看视频 | 可以在线观看的黄色 | 中国少妇初尝黑人巨大 | 欧美精品色视频 | 亚洲美女av在线 | 天天插日日干 | 在线一级视频 |