一、實(shí)驗(yàn)?zāi)康?span lang="EN-US">
多表查詢語句可以分為連接查詢、嵌套查詢和組合查詢。
本次實(shí)驗(yàn)了解SQL語言的SELECT語句對(duì)數(shù)據(jù)的查詢,學(xué)會(huì)利用SQL Server 2000的查詢分析器對(duì)數(shù)據(jù)庫(kù)SPJ中的表進(jìn)行簡(jiǎn)單查詢
二、實(shí)驗(yàn)內(nèi)容
1.熟練運(yùn)用非等值連接和等值連接,外查詢
2. 無關(guān)子查詢
3. 有關(guān)子查詢
4. 組合查詢
三、實(shí)驗(yàn)任務(wù)
1、 查詢與供應(yīng)商S1提供相同零件的供應(yīng)商編號(hào)和姓名
select sno,sname from s
where not exists(
select * from spj x
where sno='s1'and not exists(
select * from spj
where sno=s.sno and pno=x.pno))
2、查詢金額balance最多的項(xiàng)目名稱
select jname from j
where balance >= (select max(balance) from j )
select jname from j
where balance >= all(select balance from j)
3 分別使用等值連接,無關(guān)、有關(guān)子查詢?nèi)N方式,查詢使用了p3零件的工程名稱
select jname from j
where jno in (select jno from spj where pno='p3')
4、使用三種方法求供應(yīng)零件給工程J1,且零件顏色為紅色的供應(yīng)商名
select sname from s ,p,j,spj
where s.sno=spj.sno and p.pno=spj.pno and j.jno=spj.jno and j.jno='j1'and color='紅色'
5、使用三種方法求至少使用了零件編號(hào)為p3和p5的工程編號(hào)
select distinct jno from j
where jno in ( select jno from spj where pno='p3 'and pno='p5')
6、通過子查尋,查尋不使用編號(hào)p3零件的工程編號(hào)jno和名稱jname
select jno , jname from j
where jno not in ( select jno from spj where pno='p3 ')
7、求使用了全部零件的工程名稱
select jname from j
where not exists(
select * from p
where not exists(
select * from spj
where jno=j.jno and pno=p.pno))
8、求至少使用了供應(yīng)商's1'所供應(yīng)的全部零件的工程號(hào)jno
select jno from j
where jno in (select jno from spj where jno=spj.jno and spj.sno= 's1')
聯(lián)系客服