2024年2月21日发(作者:)
实验三:数据库综合查询
一、实验目的
1. 掌握SELECT语句的基本语法和查询条件表示方法;
2. 掌握连接查询的表示及使用;
3. 掌握嵌套查询的表示及使用;
二、实验环境
已安装SQL Server 2005 企业版的计算机;
三、实验内容
以数据库原理实验1数据为基础,请使用T-SQL 语句实现进行以下操作:
1、 查找出employee表中部门相同且住址相同的女员工的姓名、性别、职称、薪水、住址。
select _name,,,,
from employee x
where sex='F' and exists
(select * from employee y where = and ='F' and
= and _no<>_no);
2、 检索product 表和sale_item表中相同产品的产品编号、产品名称、数量、单价。
select prod_id,prod_name,qty,unit_price
from sale_item,product
where prod_id=pro_id
3、 检索product 表和sale_item表中单价高于2400元的相同产品的产品编号、产品名称、数量、单价。
select prod_id,prod_name,qty,unit_price
from sale_item,product
where prod_id=pro_id and unit_price>2400
4、 分别使用左向外连接、右向外连接、完整外部连接检索product 表和sale_item表中单价高于2400元的相同产品的产品编号、产品名称、数量、单价。并分析比较检索的结果。
select prod_id,prod_name,qty,unit_price from sale_item left outer join
product on prod_id=pro_id where unit_price>2400
select prod_id,prod_name,qty,unit_price from sale_item right outer join
product on prod_id=pro_id where unit_price>2400
select prod_id,prod_name,qty,unit_price from sale_item full outer join
product on prod_id=pro_id where unit_price>2400
5、 由sales表中查找出销售金额最高的订单。
select max(tot_amt) from sales
6、 由sales表中查找出订单金额大于“E0013业务员在1996/10/15这天所接任一张订单的金额”的所有订单,并显示承接这些订单的业务员和该条订单的金额。
select sale_id,tot_amt
from sales
where tot_amt >all
(select tot_amt from sales where sale_id='E0001' and
order_date='2013-1-1')
7、 找出公司女业务员所接的订单。
select sales.* from sales,employee where sex='f' and emp_no=sale_id
8、 找出公司中姓名相同的员工,并且依据员工编号排序相识这些员工信息。
select a.* from employee a,employee b where _name=_name and
_no<>_no order by _no
9、 找出目前业绩未超过200000元的员工。
select sale_id from sales a where(select sum(tot_amt) from sales b where
_id=_id )<20000
发布者:admin,转转请注明出处:http://www.yc00.com/web/1708506861a1570188.html
评论列表(0条)