SQLServer2008实验五模板

where Ptype in ('传动','标准');

复杂查询

1、查询订单金额大于100的顾客的名称和电话;

select Customer.Cname,Customer.Ctel from Customer,Orders

where Orders.Cno=Customer.Cno and Orders.Osum>100

2、查询所有签订订单的顾客的名称和邮编;

select distinct Customer.Cname,Customer.Czip from Customer,Orders

where Orders.Cno=Customer.Cno

3、统计每类零件的数量分别为多少;

select store.Pname,SUM(store.Pnum)零件数量 from Store,Orders

where store.Pno=Orders.Pno group by store.Pname,store.Pnum

4、统计每个顾客签订订单的次数;

select Customer.Cname,count(*) 订单次数 from Customer,Orders

where Customer.Cno=Orders.Cno

group by Customer.Cname,Customer.Cno

5、查询所有顾客签订订单的情况(包括没有签订订单的顾客);

select *

from Customer,Orders

where Customer.Cno=Orders.Cno or Customer.Cno!=Orders.Cno

6、查询没有卖过一次的零件号(没有订单);

select distinct store.Pno from Store,Orders where store.Pno not in

(select distinct store.Pno from Store,Orders where store.Pno=Orders.Pno)

7、查询每个顾客签订订单的金额总数;

select Orders.Cno,SUM(Orders.Osum)金额总数 from Orders,Customer

where Orders.Cno=Customer.Cno group by Orders.Cno

8、查询所有订单金额的平均值;

select Orders.Cno,AVG(Orders.Osum)订单金额 from Orders,Customer

where Customer.Cno=Orders.Cno group by Orders.Cno

9、查询至少签订过两次订单的顾客信息。

select customer.Cno,Cname,Ctel,Caddr,czip from Customer,Orders

where Customer.Cno=Orders.Cno

group by Customer.Cno,Cname,Ctel,Caddr,Czip having COUNT(*)>=2

视图

1.使用SSMS创建视图向导

通过SSMS的Create View Wizard创建新视图

1) 在SSMS中,展开“数据库”后,在视图处单击鼠标右键。

2),双击菜单“创建视图”

3)选择表order

4)选择字段Ono, Cno, Pno, Onum。


SQLServer2008实验五模板.doc 将本文的Word文档下载到电脑
搜索更多关于: SQLServer2008实验五模板 的文档
相关推荐
相关阅读