《zucc-数据库pta作业(共8页).docx》由会员分享,可在线阅读,更多相关《zucc-数据库pta作业(共8页).docx(8页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、精选优质文档-倾情为你奉上10-1查询订单表中的平均运费(20分)查询订单表(orders)的平均运费,并将其重命名为avgFreightSELECT AVG(Freight) AS avgFreightFROM orders;10-2查询国家为Mexico、Germany的客户数量(20分)查询出顾客表(customers)中查询国家(Country)为Mexico、Germany的客户数量,并重命名为custCount提示:请使用SELECT语句作答。select count(Country)as custCountfrom customerswhere Country in (Mexic
2、o,Germany);10-3查找产品表中最低的单价(20分)在产品表(products)中查询最低的单价(UnitPrice),并重命名为minUnitPrice提示:请使用SELECT语句作答。select min(UnitPrice) as minUnitPricefrom products;10-4查询产品表中最大库存量(20分)在产品表(products)中查询最多的库存数量(UnitsInStock),并重命名为maxUnitsInStock提示:请使用SELECT语句作答。select max(UnitsInStock)as maxUnitsInStockfrom product
3、s;10-5查找订单表中每位顾客的平均运费(20分)查询订单表(orders)中每位顾客的平均运费,结果显示为顾客编号(CustomerID)和平均运费(avgFreight)提示:请使用SELECT语句作答。select CustomerID,avg(Freight) as avgFreightfrom ordersgroup by CustomerID;10-6统计顾客表中每个国家的顾客数量(20分)查询出顾客表(customers)中查询每个国家的客户数量,显示为国家(Country)和客户数量(custCount)提示:请使用SELECT语句作答。select Country,coun
4、t(CustomerID) as custCountfrom customersgroup by Country;10-7在订单表中查找特定国家且平均运费不小于10的信息(20分)查询订单表(orders)中查找所在国家(ShipCountry)为Belgium,Switzerland,且平均运费不小于10的的顾客及运费信息,结果显示为顾客编号(CustomerID)和平均运费(avgFreight)提示:请使用SELECT语句作答。select CustomerID,avg(Freight) as avgFreightfrom orderswhere ShipCountry in (Belg
5、ium,Switzerland)group by CustomerIDhaving avg(Freight)=10;10-8统计职工表中职务的数量(20分)统计职工表(employees)中职务(Title)的个数,并重命名为countTitle提示:请使用SELECT语句作答。select count(distinct Title) as countTitle from employees 10-9查找订单表中特定顾客编号的相关信息(20分)查询订单表(orders)中以字母V打头的顾客编号(CustomerID)产生的订单信息,结果显示为顾客编号(CustomerID)和总运费(sumFr
6、eight)提示:请使用SELECT语句作答。select CustomerID,sum(Freight) as sumFreight from orders where CustomerID like V% group by CustomerID10-10查找产品表中平均订购数大于特定值的产品信息(20分)在产品表(products)中查找总订购数量大于15的产品信息,显示为:产品编号(ProductID),和总订货数量(重命名为sumUnitsOnOrder)提示:请使用SELECT语句作答。select ProductID,sum(UnitsOnOrder) sumUnitsOnOrde
7、r from products group by ProductIDhaving sumUnitsOnOrder1510-11在订单详细信息表中查找包含产品种类数超过特定值的订单信息(20分)在订单详情表(orderdetails)中查找订单中包含的不同产品的个数超过2的订单信息,显示订单号(OrderID)和总数量(重命名为totalQuantity)select OrderID,sum(Quantity) as totalQuantity from orderdetails group by OrderID HAVING count(ProductID) 210-12查找职员信息及其直接上
8、级的相关信息(20分)这是一个SQL编程题模板。请在这里写题目描述。例如:本题目要求编写SQL语句, 检索出Student表中所有符合id 50的记录。提示:请使用SELECT语句作答。SELECT A.LastName,A.FirstName,A.ReportsTo EmployeeID,B.TitleFROM employees A,employees BWHERE A.ReportsTo=B.EmployeeID10-13查询供应商及其供应的产品情况(20分)查找提供产品的各个供应商名称及其供应的产品,显示为:产品编号(ProductID),产品名称(ProductName),供应商编号
9、(SupplierID),公司名称(CompanyName),提示:请使用SELECT语句作答。select products.ProductID,products.ProductName,suppliers.SupplierID,suppliers.CompanyName from products,supplierswhere suppliers.SupplierID = products.SupplierID10-14查询特定供应商及其供应的产品情况(20分)查找来自国家(Country)为Japan、USA各个供应商名称及其供应的产品,显示为:供应商编号(SupplierID),公司名
10、称(CompanyName),产品编号(ProductID)和产品名称(ProductName)提示:请使用SELECT语句作答。select products.ProductID,products.ProductName,suppliers.SupplierID,suppliers.CompanyName from products,supplierswhere suppliers.SupplierID = products.SupplierIDand suppliers.Country in (Japan,USA)10-15统计各个供应商及其供应情况(20分)统计各个国家(Country)
11、的供应商的供应产品情况,显示为:国家(Country),库存总量(重命名为sumUnitsInStock),平均单价(重命名为avgUnitPrice)提示:请使用SELECT语句作答。select suppliers.Country,sum(products.UnitsInStock) as sumUnitsInStock,avg(products.UnitPrice) as avgUnitPricefrom products,supplierswhere suppliers.SupplierID = products.SupplierIDgroup by suppliers.Country
12、10-16查询客户的订单情况(20分)查找客户的订单情况,显示为:顾客编号(CustomerID),公司名称(CompanyName),订单编号(OrderID),员工编号(EmployeeID)提示:请使用SELECT语句作答。SELECT B.CustomerID,B.CompanyName,A.OrderID,A.EmployeeIDFROM orders A,customers BWHERE A.CustomerID=B.CustomerID AND A.ShipCity=B.CityORDER BY B.CustomerID ASC10-17统计客户的订单信息(20分)统计客户的订单
13、情况,显示为:公司名称(CompanyName),订单数量(重命名为countOrder),平均运费(重命名为avgFreight)提示:请使用SELECT语句作答。SELECT CompanyName,COUNT(OrderID) AS countOrder,AVG(Freight) AS avgFreightFROM orders O,customers CWHERE O.CustomerID=C.CustomerIDGROUP BY CompanyName10-18查找每位领导的直接下属数量(20分)查询每位领导的直接下属数量,显示:领导的员工编号(EmployeeID),下属数量(重命
14、名为(countSub)提示:请使用SELECT语句作答。SELECT B.EmployeeID,count(A.ReportsTo) as countSubFROM employees A,employees BWHERE A.ReportsTo=B.EmployeeIDgroup by B.EmployeeID10-19查询特定订单的详细信息(20分)查找城市(City)是Madrid的顾客,所下的订单详细信息,显示为:顾客编号(CustomerID),公司名称(CompanyName),订单编号(OrderID),产品编号(ProductID)提示:请使用SELECT语句作答。select customers.CustomerID,customers.CompanyName,orderdetails.OrderID,orderdetails.ProductIDfrom orders,orderdetails,customerswhere orders.ShipCity = Madridand orders.OrderID = orderdetails.OrderIDand orders.CustomerID = customers.CustomerID专心-专注-专业