数据库习题及答案(查询语句).docx

  1. 1、本文档共49页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
数据库习题及答案(查询语句)

--1.在产品表中检索所有产品名称以字符串’en’或’ton’结尾的产品,并按单价降序排序。select * from Products where ProductName like %en% or ProductName like %ton%order by UnitPrice desc--2.根据产品表,在单价$15~$25之间的产品中随机检索个产品。--利用随机函数NewID()select top 5 * from Products where UnitPrice between 15 and 25order by NewID()--3.在客户表中检索所有美国客户来自于哪些城市。--使用distinct去掉重复记录select distinct City from Customers where Country=USA--4.在供应商表中检索所有邮政编码(Postalcode)是字母开头的而且传真号(Fax)为非空(NULL)的供应商信息。--使用like和is not nullselect * from Suppliers where postalcode like [A-Z]% and Fax is not null--5.在员工表中检索所有职位为Sales Representative的这些员工的主管(ReportsTo)的编码。--使用distinct去掉重复记录select distinct ReportsTo from Employees where title=Sales Representative--6.在订单表中检索所有在年月日之前需要发货但还没有发货的订单信息。--注:不能省略ShippedDate这个条件,它的含义为:在年月日之后发货的订单在当时(年月日之前)等同于还没有发货select * from Orders where RequiredDate=2009-06-30 and (ShippedDate is null or ShippedDate=2009-06-30)--7.按产品类别编码对产品表进行分组汇总,检索平均单价$30元以上的所有产品类别。--使用group by和havingselect CategoryID,AVG(UnitPrice) from Productsgroup by CategoryIDhaving AVG(UnitPrice)=30--8.按供应商和产品类别进行分组汇总,检索每个供应商提供的每类产品的平均单价。--使用带两个关键字的group byselect SupplierID,CategoryID,AVG(UnitPrice) from Productsgroup by SupplierID,CategoryIDorder by SupplierID,CategoryID--9.按供应商编码对产品表进行分组汇总,检索哪些供应商至少提供了两个单价在$20以下的产品。--在使用group by的查询语句中,注意where和having的出现顺序位置select SupplierID from Productswhere UnitPrice20group by SupplierIDhaving count(*)=2--10.按客户和月份对订单表进行分组汇总,统计检索年度每个客户每月的订单数量。--使用带两个关键字的group byselect CustomerID,Month(OrderDate) as Month,COUNT(*) as NumberofOrders from Orderswhere OrderDate between 2009-01-01 and 2009-12-31group by CustomerID,MONTH(OrderDate)order by CustomerID,MONTH(OrderDate)--11.统计检索年度每个产品的订单数和订单额。--使用带where的group byselect ProductID,COUNT(*) as NumberofOrders,SUM(Amount) as Amountfrom Orders as ajoin OrderItems as b on a.OrderID=b.OrderIDwhere OrderDate between 2009-01-01 and 2009-12-31group by ProductIDorder by ProductID--12.统计检索年销售额大于$150万的员工姓名。--使用带where、having和多表连接的group byselect Firstname+ +Lastname as EmployeeName from Orders as ajoi

文档评论(0)

gangshou + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档