- --(1) 查询日期为2001年5月22日的订单详情。
- select *
- from OrderDetail
- where cOrderNo in(select cOrderNo
- from orders
- where datepart(yyyy,dOrderDate)=2001
- and datepart(mm,dOrderDate)=5
- and datepart(dd,dOrderDate)=22)
- --(2) 查询订单总额超过75的订单详情。
- select *
- from OrderDetail
- where cOrderNo in(select cOrderNo
- from orders
- where mTotalCost>=75)
- --(3) 订单延误将按照总价值mTotalCost的5倍赔偿,查询每份订单的订单号和需要赔偿的金额
- select DelayOrder=cOrderNo,Compensation=mTotalCost*5
- from Orders x
- where DateDiff(day,dOrderDate,dExpDelDate)>
- (select iMaxDelDays
- from shippingmode y
- where x.cShippingModeId=y.cModeId)
- --(4) 查询以‘I’开头,国家名称由五个字母构成的国家ID和名称。
- select *
- from Country
- where 'I'=left(cCountry,1) and len(cCountry)=5
- --(5) 查询Shipment表中dActualDeliveryDate为空的记录。
- select *
- from shipment
- where dActualDeliveryDate is null
- --(6) 对于PickofMonth表,查询月销售量最高的玩具ID和销售的月份和年份。
- select cToyID,siMonth,iYear
- from pickofmonth
- where iTotalSold>=(select Max(iTotalSold)
- from pickofmonth)
- --(7) 对于PickofMonth表,统计2000年销售的玩具的总数量。
- select '2000年销售总额'=sum(itotalSold)
- from pickofmonth
- where iyear=2000
- --(8) 对于Toys表,查询玩具的最高售价,最低售价,和平均售价。
- select '玩具最高售价'=MAX(mToyRate),
- '玩具最低售价'=MIN(mToyRate),
- '玩具平均售价'=AVG(mToyRate)
- from toys
- --(9) 对于Shopper表,统计‘California’州的购买者人数。
- select '加州购买人数'=count(*)
- from shopper
- where cState='California'
- --(10) 对于PickofMonth表,查询2001的销售记录,要求按照月销售额按照从小到大的顺序显示。
- select *
- from pickofmonth
- where iYear=2001
- order by iTotalSold desc
- --(11) 对于Shippingrate表,计算每个国家的每磅的平均运费。
- select cCountryID ,'平均运费'=avg(mRatePerPound)
- from shippingrate
- group by cCountryID