打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
数据查询2之多表查询

数据查询2之多表查询

一、实验目的

多表查询语句可以分为连接查询、嵌套查询和组合查询。

本次实验了解SQL语言的SELECT语句对数据的查询,学会利用SQL Server 2000查询分析器对数据库SPJ中的表进行简单查询

 

二、实验内容

1.熟练运用非等值连接和等值连接,外查询

2. 无关子查询

3. 有关子查询

4. 组合查询

三、实验任务

1 查询与供应商S1提供相同零件的供应商编号和姓名

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最多的项目名称

select jname from j

   where balance >= (select max(balance) from j )

 

select jname from j

   where balance >= all(select balance from j)

 

 

3 分别使用等值连接,无关、有关子查询三种方式,查询使用了p3零件的工程名称

select jname from j

   where jno in (select jno from spj where pno='p3')

 

4、使用三种方法求供应零件给工程J1,且零件颜色为红色的供应商名

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、使用三种方法求至少使用了零件编号为p3p5的工程编号

select distinct jno from j

where jno in (  select jno from spj where pno='p3 'and pno='p5')

 

6、通过子查寻,查寻不使用编号p3零件的工程编号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、求至少使用了供应商's1'所供应的全部零件的工程号jno

select jno from j

where jno in (select jno from spj where jno=spj.jno and spj.sno= 's1')

     

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
sql
数据库系统概论课后习题答案(王珊、萨师煊)
sql小知识
数据库面试题笔试题
专题:SQL之EXISTS 供应商和学生考试 的解说为例
大学数据库考试复习题
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服