亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb

首頁 > 開發 > 綜合 > 正文

練習用基礎SQL語句

2024-07-21 02:50:08
字體:
來源:轉載
供稿:網友
練習用基礎SQL語句

本文語句大部分SQL語句來自《數據庫系統概論》(第四版)王珊&薩師煊 ,是我們上課用的教材,感覺很不錯,總結了其中第三章的SQL語句,比較實用,希望對大家有幫助??偨Y如下,可以用來學習基礎的SQL語句。

建立數據庫

CREATE DATABASE DB_Student

建立表

CREATE TABLE Student

(Sno CHAR(9) PRIMARY KEY,--主碼

Sname CHAR(20) UNIQUE,--唯一值

Ssex CHAR(2),

Sage SMALLINT,

Sdept CHAR(20)

);

CREATE TABLE Course

(Cno CHAR(4) PRIMARY KEY,

Cname char(40),

Cpno CHAR(4),

Ccredit SMALLINT,

FOREIGN KEY (Cpno) REFERENCES Course(Cno)

);

CREATE TABLE SC

(Sno CHAR(9),

Cno CHAR(4),

Grade SMALLINT,

PRIMARY KEY (Sno,Cno),

FOREIGN KEY (Sno) REFERENCES Student(Sno),--外碼

FOREIGN KEY (Cno) REFERENCES Course(Cno)

);

數據

表操作

alter table Student add S_entrance date--增加列

alter table student alter column Sage int--修改字段類型

alter table course add unique (Cname)--增加唯一性約束

drop table Student--刪除基本表

drop table student cascade--刪除基本表及相關依賴對象

創建索引

drop index stusname

查詢數據

select sno,sname from student

select sname,sno,sdept from student

select sname,2004-sage from student

select sname,'Year of Birth:',2004-sage, lower(sdept) from student--查詢結果第二列是一個算數表達式

select sname name,'Year of Birth:' BIRTH,2004-sage birthday,LOWER(sdept) department from student--LOWER()小寫字母

select sno from sc

select distinct sno from sc--消除重復行

select sno from sc

select all sno from sc

select sname from student where sqept='CS'

--=、>、<、>=、<=、!=、<>、!>、!< 比較的運算符

select sname,sage from student where sage<20

select distinct sno from sc where sage<20

select sname,sdept,sage from student where sage between 20 and 23

select sname,sdept,sage from student where sage not between 20 and 23

select sname,ssex from student where sdept in ('CS','MA','IS')

select sname,sage from student where sdept not in('CS','MA','IS')

select * from student where sno like '200215121'

select * from student where sno='200215121'

--字符匹配

--% 任意長度字符串,_ 任意單個字符,ESCAPE 轉義字符

select sname,sno,ssex from student where sname like '劉%'

select sname from student where sname like '歐陽__'

select sname,sno from student where sname like '__陽%'

select sname,sno,ssex from student where sname not like '劉%'

select cno,ccredit from course where cname like 'DB/_design' escape '/'

select * from course where cname like 'DB/_%i__' escape '/'

select sno,cno from sc where grade is null --null 空值

select sno,cno from sc where grade is not null

select sname from student where sdept='CS' and sage<20

select sname,sage from studnet where sdept='CS' or sdept='MA' or sdept='IS'

select sno,grade from sc where cno='3' order by grade desc -- order by 排序

select * from student order by sdept,sage desc --空值最大

--聚集函數

select count(*) from student -- count() 行數

select count(distinct sno) from sc

select avg(grade) from sc where cno='1' -- avg() 平均數

select max(grade) from sc where cno='1' -- max() 最大值

select sum(Ccredit) from sc,course where sno='200215012' and sc.cno=course.cno -- sum() 總數

--分組

select cno,count(sno) from sc group by cno

select sno from sc group by sno having count(*) >3 --having 給出選擇組的條件

--連接查詢

select student. *,SC.* FROM STUDENT,SC where student.sno=sc.sno

select student.sno,sname,ssex,sage,sdept,cno,grade from student,sc where student.sno =sc.sno

select first.cno,second.cpno from course first,course second fwhere first.cpno=second.cno -- 自身連接

select student.sno,sname,ssex,sage,sdept,cno,grade from student left out join sc in (student.sno=sc.sno)--外連接

--from student left out join sc using (sno)

select student.sno,sname from student,sc where student.sno=sc.sno and sc.cno='2' and sc.grade>90

select student.sno,sname,cname,grade from student,sc,course where student.sno=sc.sno and sc.cno=course.cno

select sname from student where sno in (select sno from sc shere con='2')

select sdept from student where sname='劉晨'

select sno.sname,sdept from student where sdept='CS'

--嵌套查詢

select sno,sname,sdept from student where sdept in (select sdept from studnet where sname='劉晨')

select sno,sname,sdept from student where sdept in ('CS')

select s1.sno,s1.sname,s1.sdept from student s1,student s2 where s1.sdept =s2.sdept and s2.sname='劉晨'

select sno,sname from student where sno in (select sno from sc where cno in(select cno from course where cname='信息系統'))

select student.sno,sname from student ,sc,course where student.sno=sc.sno and sc.cno =course.cno and course.cname='信息系統'

--內查詢的結果是一個值,因此可以用=代替in

select sno,sname,sdept from student where sdpet=(se3lect sdept from studnet where sname='劉晨')

select sno,sname,sdept from student where(select sdept from student where sname='劉晨')=sdept

select sno,cno from sc x where grade >=(select avg(grade) from sc y where y.sno=x.sno)

select avg(grade) from sc y where y.sno='200215121'

select sno,cno from sc x where grade>=88

select sname,sage from student where sage <ANY (SELECT sage from student where sdept='CS') and sdept <>'CS'

select sname,sage from student where sage<(select max(sage) from student where sdept='CS') and sdept <> 'CS'

select sname,sage from student where sage < all (select sage from student where sdept ='CS')

select sname,sage from student where sage<(select min(sage) from student where sdept='CS') and sdept <>'CS'

select sname from student where exists(select * from sc where sno=student.sno and cno='1')

select sname from student where not exists (select * from sc where sno=student.sno and cno='1')

select sno.sname,sdept from student s1 where exists(select * from studetn s2 where s2.sdept=s1.sdept and s2.sname='劉晨')

select sname from student where not exists (select * from course where not exists(select * from sc where sno=student.sno and cno=course.cno))

select distinct sno frome sc scx where not exists (select * from sc scy where scy.sno='200215122' and not exists(select * from sc scz where scz.sno=scx.sno and scz.cno=scy.cno))

http://zxlovenet.cnblogs.com

集合查詢

select * from student where sdept ='CS' union select * from student where sage<=19 --union并操作

se

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb
疯狂蹂躏欧美一区二区精品| 精品国偷自产在线视频99| 国产人妖伪娘一区91| 成人免费直播live| 国产在线视频一区| 国内精品久久久久久久久| 亚洲自拍欧美另类| 久久久久免费精品国产| 2019国产精品自在线拍国产不卡| 精品久久久久久中文字幕大豆网| 国产精品久久久久久婷婷天堂| 亚洲国产精品久久久久| 国产成人精品视频在线| xxxxxxxxx欧美| 国产美女主播一区| 精品少妇一区二区30p| 欧美性生交大片免网| 欧美午夜性色大片在线观看| 久久久女人电视剧免费播放下载| 影音先锋日韩有码| 91精品国产91久久| 国产精品h在线观看| 这里只有精品在线观看| 亚洲最大成人网色| 亚洲国产小视频在线观看| 亚洲精品国产欧美| 超碰日本道色综合久久综合| 成人av番号网| 欧美色视频日本高清在线观看| 精品欧美aⅴ在线网站| 国产精品天天狠天天看| 九九热精品视频国产| 国产精品久久9| 中文字幕久热精品在线视频| 欧美激情免费在线| 欧美日韩日本国产| 精品视频久久久久久久| 国产极品jizzhd欧美| 国产+成+人+亚洲欧洲| 久久综合色88| 国产一区二区丝袜高跟鞋图片| 亚洲人午夜精品| 欧美一级片在线播放| 欧美日韩成人免费| 日韩高清电影好看的电视剧电影| 欧美日韩美女在线| 国产香蕉97碰碰久久人人| 亚洲人成电影网站色www| 久久九九亚洲综合| 91av视频在线免费观看| 国产欧美韩国高清| 日韩免费在线播放| 一本色道久久88精品综合| 亚洲精品久久久久国产| 久久精品一偷一偷国产| 成人网在线免费看| 亚洲人成在线播放| 九九九久久国产免费| 久久久久亚洲精品| 26uuu国产精品视频| 国产精品老牛影院在线观看| 国产成人精品久久亚洲高清不卡| 国产精品va在线| 亚洲影院污污.| 亚洲免费一在线| 伊人久久大香线蕉av一区二区| 欧美成人黑人xx视频免费观看| 久久人人爽亚洲精品天堂| 久久久久www| 久久精品国产免费观看| 欧美激情免费观看| 永久免费精品影视网站| 成人高h视频在线| 亚洲爱爱爱爱爱| 亚洲国产天堂网精品网站| 日韩av在线一区| 欧美日韩国产成人在线观看| 欧美日韩综合视频网址| 国产精品99久久久久久久久久久久| www国产精品视频| 国产精品视频区| 久久久中文字幕| 51色欧美片视频在线观看| 国产丝袜一区视频在线观看| 亚洲精品自产拍| 在线观看欧美成人| 国产成人精品一区二区三区| 久久av红桃一区二区小说| 狠狠综合久久av一区二区小说| 精品亚洲一区二区三区在线观看| 成人激情免费在线| 日本久久久久久久久| 久热精品视频在线观看一区| 久久久久久久久久久91| 伊人伊成久久人综合网站| 精品国产一区二区三区久久久| 欧美国产精品va在线观看| 国产丝袜视频一区| 亚洲国产精品99久久| 日韩电影视频免费| 日韩av在线免费看| 中文字幕精品一区二区精品| 欧美日韩中国免费专区在线看| 精品国产欧美一区二区三区成人| 欧美性极品少妇精品网站| 欧美一级电影在线| 国产精品中文在线| 日韩欧美在线中文字幕| 欧美大尺度激情区在线播放| 久久成人国产精品| 欧美性一区二区三区| 亚洲一品av免费观看| 隔壁老王国产在线精品| 国产精品久久久久久久app| 亚洲欧洲午夜一线一品| 国产精品视频xxx| 国产精品第1页| 亚洲国产天堂久久国产91| 国产99久久精品一区二区 夜夜躁日日躁| 日韩精品中文字幕在线观看| 在线亚洲国产精品网| 亚洲人成电影网站| zzjj国产精品一区二区| xxav国产精品美女主播| 精品视频久久久| 中文字幕欧美亚洲| 久久影视电视剧凤归四时歌| 国产美女高潮久久白浆| 亚洲乱码一区二区| 97在线观看视频| 亚洲理论片在线观看| 亚洲国产精品成人精品| 欧美激情中文字幕乱码免费| 欧美床上激情在线观看| 成人精品视频99在线观看免费| 国产一区视频在线播放| 精品国产31久久久久久| 日韩中文字幕国产精品| 欧美激情一区二区三级高清视频| 欧美在线视频播放| 亚洲国产婷婷香蕉久久久久久| 久久久久久久久中文字幕| 国产日产久久高清欧美一区| 91精品国产自产在线老师啪| 亚洲自拍小视频免费观看| 91沈先生作品| 欧美最近摘花xxxx摘花| 91av在线看| 久久免费视频在线观看| 日韩美女在线观看| 欧美一区二区视频97| 国产精品久久久久久久av大片| 亚洲自拍偷拍一区| 欧美一区二粉嫩精品国产一线天| 国产精品劲爆视频| 国产视频亚洲视频| 国产成人精品一区| 国产欧美一区二区三区四区| 欧美香蕉大胸在线视频观看| 久久男人资源视频| 色偷偷av一区二区三区| 欧美成人剧情片在线观看| 国产一区私人高清影院| 这里只有精品久久|