全球玩具贸易查询作业

来源:互联网 发布:思途旅游网站源码 编辑:程序博客网 时间:2024/04/30 06:21
Code:
  1. --(1) 查询日期为2001年5月22日的订单详情。  
  2. select *  
  3. from OrderDetail  
  4. where cOrderNo in(select cOrderNo   
  5.                     from orders  
  6.                     where datepart(yyyy,dOrderDate)=2001   
  7.                             and datepart(mm,dOrderDate)=5  
  8.                             and datepart(dd,dOrderDate)=22)  
  9.   
  10. --(2) 查询订单总额超过75的订单详情。  
  11. select *  
  12. from OrderDetail  
  13. where cOrderNo in(select cOrderNo   
  14.                 from orders  
  15.                 where mTotalCost>=75)  
  16.   
  17. --(3) 订单延误将按照总价值mTotalCost的5倍赔偿,查询每份订单的订单号和需要赔偿的金额  
  18. select DelayOrder=cOrderNo,Compensation=mTotalCost*5  
  19. from Orders x  
  20. where DateDiff(day,dOrderDate,dExpDelDate)>  
  21.     (select iMaxDelDays   
  22.      from shippingmode y  
  23.      where x.cShippingModeId=y.cModeId)  
  24.   
  25. --(4) 查询以‘I’开头,国家名称由五个字母构成的国家ID和名称。  
  26. select *  
  27. from Country  
  28. where 'I'=left(cCountry,1) and len(cCountry)=5  
  29.   
  30. --(5) 查询Shipment表中dActualDeliveryDate为空的记录。  
  31. select *   
  32. from shipment  
  33. where dActualDeliveryDate is null  
  34.   
  35.   
  36. --(6) 对于PickofMonth表,查询月销售量最高的玩具ID和销售的月份和年份。  
  37. select cToyID,siMonth,iYear  
  38. from pickofmonth   
  39. where iTotalSold>=(select Max(iTotalSold)  
  40.                     from pickofmonth)  
  41.   
  42. --(7) 对于PickofMonth表,统计2000年销售的玩具的总数量。  
  43. select '2000年销售总额'=sum(itotalSold)   
  44. from pickofmonth  
  45. where iyear=2000  
  46.   
  47. --(8) 对于Toys表,查询玩具的最高售价,最低售价,和平均售价。  
  48. select '玩具最高售价'=MAX(mToyRate),  
  49.         '玩具最低售价'=MIN(mToyRate),  
  50.         '玩具平均售价'=AVG(mToyRate)  
  51. from toys  
  52.   
  53. --(9) 对于Shopper表,统计‘California’州的购买者人数。  
  54. select '加州购买人数'=count(*)  
  55. from shopper  
  56. where cState='California'  
  57.   
  58. --(10) 对于PickofMonth表,查询2001的销售记录,要求按照月销售额按照从小到大的顺序显示。  
  59. select *   
  60. from pickofmonth  
  61. where iYear=2001  
  62. order by iTotalSold desc  
  63.   
  64. --(11) 对于Shippingrate表,计算每个国家的每磅的平均运费。  
  65. select cCountryID ,'平均运费'=avg(mRatePerPound)  
  66. from shippingrate  
  67. group by cCountryID  

 

 

原创粉丝点击