




已阅读5页,还剩3页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
下图是企业订单管理系统的E-R图,提供对职工信息、客户信息、供应商信息、产品信息、订单信息、订单明细进行管理。描述为主键,描述为外键,外键约束通过图下箭头线进行标注。其中职员信息表中的sex取值为m或f,表示为男和女。创建脚本如下:/*=*/* Table: 供应商信息表Supplier */*=*/create table Supplier ( SupplierID char(5) not null, SupplierName varchar(50) not null, Phone varchar(20) not null, Address varchar(50) null, PostalCode varchar(15) null, City varchar(20) null, constraint PK_Supplier primary key (SupplierID)go/*=*/* Table: 产品信息表Products */*=*/create table Products ( ProductID char(5) not null, ProductName varchar(50) not null, SupplierID char(5) not null, constraint PK_Products primary key (ProductID), constraint FK_PRODUCTS_SUPPLIER foreign key (SupplierID) references Supplier (SupplierID)go/*=*/* Table: 客户信息表Customers */*=*/create table Customers ( CustomerID char(5) not null, CustomerName varchar(50) not null, Phone varchar(20) not null, Address varchar(50) null, PostalCode varchar(15) null, City varchar(20) null, constraint PK_Customers primary key (CustomerID)go/*=*/* Table: 部门信息表Department */*=*/create table Department ( DepartmentID char(5) not null, DepartmentName char(50) not null, constraint pk_Department primary key (DepartmentID)go/*=*/* Table: 职员信息表Employees */*=*/create table Employees ( EmployeeID char(5) not null, EmployeeName varchar(30) not null, sex char(1) not null, BirthDate smalldatetime null, HireDate smalldatetime null, DepartmentID char(5) not null, Title varchar(20) null, Address varchar(50) null, LinkPhone varchar(20) null, Salary smallmoney not null, constraint PK_Employees primary key (EmployeeID), constraint FK_EMPLOYEE_DEPTMENT foreign key (DepartmentID) references Department (DepartmentID), constraint CK_Sex check (sex in (M,F)go/*=*/* Table: 订单表Orders */*=*/create table Orders ( OrderID char(5) not null, CustomerID char(5) not null, EmployeeID char(5) not null, OrderDate smalldatetime not null, RequiredDate smalldatetime null, Amount numeric(12,2) not null, constraint PK_Sales primary key (OrderID), constraint FK_ORDERS_CUSTOMER foreign key (CustomerID) references Customers (CustomerID), constraint FK_ORDERS_EMPLOYEE foreign key (EmployeeID) references Employees (EmployeeID)go/*=*/* Table: 订单明细表OrderDetails */*=*/create table OrderDetails ( OrderID char(5) not null, ProductID char(5) not null, UnitPrice numeric(12,2) not null, Quantity smallint not null, constraint pk_saledetails primary key (OrderID, ProductID), constraint FK_ORDERDETAILS_ORDERS foreign key (OrderID) references Orders (OrderID), constraint FK_ORDERDETAILS_PRODUCTS foreign key (ProductID) references Products (ProductID)Go根据上图完成如下操作:-1、查找员工的编号、姓名、部门和出生日期,如果出生日期为空值,显示日期不详,并按部门排序输出,日期格式为yyyy-mm-dd。 select EmployeeID ,EmployeeName ,DepartmentID , isnull(convert(char(10),BirthDate,120),日期不详) BirthDate from employees order by DepartmentID /判断空值和数据类型转换函数 -2、查找与喻自强在同一个单位的员工ID、员工姓名、性别、部门和职称 -3、按部门进行汇总,输出部门名称和统计部门总工资。 select DepartmentName,sum(salary) TotalSalaryfrom employees,departmentwhere employees.departmentID=department.departmentID group by DepartmentName -4、查找商品名称为14寸显示器商品的销售情况,显示该商品的编号、销售数量、单价和金额 select a.ProductID,Quantity,UnitPrice,UnitPrice*Quantity totprice from OrderDetails a,Products b where a.ProductID=b.ProductID and ProductName=14寸显示器 -5、在销售明细表中按产品编号进行汇总,统计每种产品的销售数量和金额 select ProductID,sum(Quantity) totqty,sum(Quantity*UnitPrice) totprice from OrderDetails group by ProductID -6、按客户编号统计每个客户1996年的订单总金额超过50万的客户编号和订单总金额 select CustomerID,sum(Amount) totprice from Orders where convert(char(4),OrderDate,120)=1996 group by CustomerIDhaving sum(Amount)500000-如何插入日期? 还可year(orderdate)=1996! -7、查找有销售记录的客户编号、名称和订单总额 select a.CustomerID,CustomerName,sum(Amount) totprice from Customers a,Orders b where a.CustomerID=b.CustomerID group by a.CustomerID,CustomerName -8、查找在1997年中有销售记录的客户编号、名称和订单总额 -9、查找一次销售最大的销售记录 select OrderID,CustomerID,EmployeeID,Amount from Orders where Amount= (select max(Amount) from Orders) -10、查找至少有3次销售的业务员名单和销售日期 select EmployeeName,OrderDate from employees a,Orders b where a.EmployeeID=b.EmployeeID and a.EmployeeID in (select EmployeeID from Orders group by EmployeeID having count(*)=3) order by EmployeeName -11、用存在量词Exists查找没有订货记录的客户名称 select CustomerName from Customers a where not exists (select * from Orders b where a.CustomerID=b.CustomerID) -12、使用左外连接查找每个客户的客户编号、名称、订货日期、订单金额、订货日期,日期格式为yyyy-mm-dd,按客户编号排序,同一客户再按订单降序排序输出 select a.CustomerID,CustomerName,convert(char(10),OrderDate,120) OderDate,Amount from Customers a left outer join Orders b on a.CustomerID=b.CustomerID order by a.CustomerID,Amount desc -13、查找产品“16M DRAM”的销售情况,要求显示相应的销售员的姓名、性别,销售日期、销售数量和金额,其中性别用男、女表示 select EmployeeName 姓名, 性别= case a.sex when m then 男 when f then 女 else 未 end, 销售日期= isnull(convert(char(10),b.OrderDate,120),日期不详), Quantity 数量, Quantity*UnitPrice as 金额 from employees a, Orders b, OrderDetails c,Products d where d.ProductName=16M DRAM and d.ProductID=c.ProductID and a.EmployeeID=b.EmployeeID and b.OrderID=c.OrderID) -14、查找每个人的销售记录,要求显示销售员的编号、姓名、性别、 -产品名称、数量、单价、金额和销售日期 select a.EmployeeID 编号,EmployeeName 姓名, 性别= case a.sex when m then 男 when f then 女 else 未 end, ProductName 产品名称,销售日期= isnull(convert(char(10),b.OrderDate,120),日期不详), Quantity 数量, Quantity*UnitPrice as 金额 from employees a left outer join Orders b on a.EmployeeID=b.EmployeeID , OrderDetails c,Products d where d.ProductID=c.ProductID and b.OrderID=c.OrderID -15、查找销售金额最大的客户名称和总货款 select CustomerName,d.cust_sum from Customers a, (select CustomerID,cust_sum from (select CustomerID, sum(Amount) as cust_sum from Orders group by CustomerID ) b where b.cust_sum = ( select max(cust_sum) from (select CustomerID, sum(Amount) as cust_sum from Orders group by CustomerID ) c ) ) d where a.CustomerID=d.CustomerID -16、查找销售总额少于1000元的销售员编号、姓名和销售额 -17、查找至少销售了3种商品的客户编号、客户名称、商品编号、商品名称、数量和金额 select a.CustomerID,CustomerName,b.ProductID,ProductName,d.Quantity,d.Quantity*d.UnitPrice TotalPrice from Customers a, Products b, Orders c, OrderDetails d where a.CustomerID=c.CustomerID and d.ProductID=b.ProductID and c.OrderID=d.OrderID and a.CustomerID in ( select CustomerID from (select CustomerID,count(distinct ProductID) prodid from (select CustomerID,ProductID from Orders e,OrderDetails f where e.OrderID=f.OrderID) g group by CustomerID having count(distinct ProductID)=3) h ) -18、查找至少与客户“世界技术开发公司”销售相同的客户编号、名称和商品编号、商品名称、数量和金额 select a.CustomerID,CustomerName,d.ProductID,ProductName,Quantity,Quantity*UnitPrice TotalPrice from Customers a, Products b, Orders c, OrderDetails d where a.CustomerID=c.CustomerID and d.ProductID=b.ProductID and c.OrderID=d.OrderID and not exists (select f.* from Customers x ,Orders e, OrderDetails f where CustomerName=世界技术开发公司 and x.CustomerID=e.CustomerID and e.OrderID=f.OrderID and not exists ( select g.* from OrderDetails g, Orders h where g.ProductID = f.ProductID and g.OrderID=h.OrderID and h.CustomerID=a.CustomerID) ) -19、查找表中所有姓刘的职工的工号,部门,薪水 select EmployeeID,EmployeeName,DepartmentID,salary from employees where EmployeeName like 刘% -20、查找所有定单金额高于20000的所有信息(包括客户编号和名称) select Customers.CustomerID,CustomerName from Orders,Customers where Orders.CustomerID=Customers.CustomerID and Amount20000 -21、统计表中员工的薪水在40000-60000之间的人数 select count(*)as 人数 from employees where salary between 40000 and 60000 -22、查询表中的每个部门的职工的平均工资,但只查询”住址”是”上海市”的员工 select DepartmentID, avg(salary) avg_sal, from employees where Address like 上海市% group by DepartmentID -23、将表中住址为上海市的员工住址改为北京市 update employees set Address = 北京市 where Address like 上海市 -24、查找业务部或会计部的女员工的基本信息。 select EmployeeID,EmployeeName, employees.DepartmentID from employees,department where employees.departmentID=department.departmentID andsex=Fand (DepartmentName in (业务,会计) -25、显示每种产品的销售金额总和,并依销售金额由大到小输出。 select ProductID ,sum(Quantity*UnitPrice) SaleTotalPrice from OrderDetails group by ProductID order by sum(Quantity*UnitPrice) desc -26、选取编号界于C0001和C0004的客户编号、客户名称、客户地址。 select CUSTOMERID,CustomerName,Address from Customers where CustomerID between C0001 AND C0004 -27、计算出一共销售了几种产品。 select count(distinct ProductID) as 共销售产品数 from OrderDetails -28、将业务部员工的薪水上调3%。 update employees set salary=salary*1.03 where DepartmentID=(select DepartmentID from department wheredepartmentName=业务) -29、由employee表中查找出薪水最低的员工信息。 select * from employees where salary= (select min(salary ) from employees ) -30、使用join查询客户姓名为客户丙所购货物的客户名称,定单金额,定货日期,电话号码 select a.CustomerID,b.Amount,b.OrderDate,a.Phone from Customers a join Orders b on a.CustomerID=b.CustomerID and CustomerName like 客户丙-31、由Orders表中查找出订单金额大于“E0013业务员在1996/10/15这天所接每一张订单的金额”的所有订单。 select * from Orders where Amountall (select Amount from Orders where EmployeeID=E0013and OrderDate=1996/10/15) order by Amount -32、计算P0001产品的平均销售单价 select avg(UnitPrice) Average from OrderDetails where ProductID=P0001 -33、找出公司女员工所接的定单 select EmployeeID,Amount from Orders where EmployeeID in (select EmployeeID from employees where sex=F) -34、找出同一天进入公司服务的员工 select a.EmployeeID,a.EmployeeName,a.HireDate from employees a join employees b on (a.EmployeeID!=b.EmployeeID and a.HireDate=b.HireDate) order by a.HireDate -35、找出目前业绩超过232000元的员工编号和姓名。 select EmployeeID,EmployeeName from employees where EmployeeID in (select EmployeeID from Orders group by EmployeeID having sum(Amount)(select avg(salary) from employees) -38、找出目前销售业绩超过40000元的业务员编号及销售业绩,并按销售业绩从大到小排序。 Select EmployeeID ,sum(Amount) SaleAmount from Orders group by EmployeeID having sum(Amount)40000 order by sum(Amount) desc -39、找出公司男业务员所接且订单金额超过2000元的订单号及订单金额。 Select OrderID,Amount From Orders ,employees Where Orders.EmployeeID=employees.EmployeeID and sex=M and Amount2000 -40、查询Orders表中订单金额最高的订单号及订单金额。 Select OrderID,Amount from Orders where Amount=(select max(Amount) from Orders) -41、查询在每张订单中订购金额超过24000元的客户名及其地址。 Select CustomerName,Address from Customers a,Orders b where a.CustomerID=b.CustomerID and Amount24000 -42、求出每位客户的总订购金额,显示出客户号及总订购金额,并按总订购金额降序排列。 Select CustomerID,sum(Amount) TotalAmout from Orders Group by CustomerID Order by sum(Amount) desc -43、求每位客户订购的每种产品的总数量及平均单价,并按客户号,产品号从小到大排列。 Select CustomerID,ProductID,sum(Quantity) TotalQuantity,sum(Quantity*UnitPrice)/sum(Quantity) AveragePrice From Orders a, OrderDetails b Where a.OrderID=b.OrderID Group by CustomerID,ProductID Order by CustomerID,ProductID -44、查询订购了三种以上产品的订单号。 Select OrderID from OrderDetails Group by OrderID Having count(*)3 -45、查询订购的产品至少包含了订单10003中所订购产品的订单。 Select distinct OrderID From OrderDetails a Where OrderID10003and not exists ( Select * from OrderDetails b where OrderID =10003 and not exists (select * from OrderDetails c where c.OrderID=a.OrderID and c.ProductID=b.ProductID) -46、在Orders表中查找出订单金额大于“E0013业务员在1996/11/10这天所接每一张订单的金额”的所有订单,并显示承接这些订单的业务员和该订单的金额。 Select EmployeeID,Amount from Orders where Amountall(select Amount from Orders where EmployeeID=E0013 and OrderDate=1996/11/10) -47、查询末承接业务的员工的信息。 Select * From employees a Where not exists (select * from Orders b where a.EmployeeID=b.EmployeeID) -48、查询来自上海市的客户的姓名,电话、订单号及订单金额。 Select CustomerName,Phone,OrderID,Amount From Customers a ,Orders b Where a.CustomerID=b.CustomerID and Address=上海市 -49、查询每位业务员各个月的业绩,并按业务员编号、月份降序排序。 Select EmployeeID,month(OrderDate) Month, sum(Amount) Gross from Orders group by EmployeeID,month(OrderDate) order by EmployeeID,month(OrderDate) desc -50、求每种产品的总销售数量及总销售金额,要求显示出产品编号、产品名称,总数量及总金额,并按产品号从小到大排列。 Select a.ProductID,ProductName,sum(Quantity) TotalQuantity,sum(Quantit
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025河南郑州航空港区招聘国有平台公司高级产业运营官及高级管理人员20人笔试参考题库附带答案详解
- 2025年河南空港数字城市开发建设有限公司第一批社会招聘20人笔试参考题库附带答案详解
- 2025年四川长虹民生物流股份有限公司招聘单证专员等岗位4人笔试参考题库附带答案详解
- 2025年中核第七研究设计院有限公司校园招聘笔试参考题库附带答案详解
- 2025年3月浙江金华市义乌市属国有企业招聘57人笔试参考题库附带答案详解
- 2025国网天津市电力公司高校毕业生招聘50人(第二批)笔试参考题库附带答案详解
- 2025四川泸州市兴泸投资集团有限公司第一次招聘16人笔试参考题库附带答案详解
- 2025内蒙古通辽环保投资有限公司招聘4人笔试参考题库附带答案详解
- 2025中电科半导体材料有限公司招聘6人(天津)笔试参考题库附带答案详解
- 2025济宁职业技术学院单招《语文》题库试题附完整答案详解(历年真题)
- 《土地变更调查讲义》课件
- 财务整账合同模板
- 2020年水利水电工程标准施工招标文件
- 《农产品安全与质量检测》课件-3.2.食品中的灰分的测定
- 钢结构厂房排水系统安装方案
- 对新员工保密基本培训
- 口耳目手足课件
- 2024-2025学年湖北省武汉二中广雅中学九年级上学期9月月考数学试题及答案
- 箱式变电站技术规范应答
- 2024年新北师大版七年级上册数学教学课件 第三章 整式及其加减 1 代数式 第1课时 代数式
- 2024 年甘肃省职业院校技能大赛高职组公共管理与服务类人力资源服务赛项竞赛规程
评论
0/150
提交评论