你是一个食物批发商的数据库开发者.每星期,公司完成不同顾客的订单.通常,每个顾客每星期定购同样数量的一定项目.偶尔,顾客定购的某个项目的数量明显少于顾客通常的数量.订单的信息储存在表invoice中,该表在sqlserver2000数据库中.创建该表的脚步如x下:CREATE TABLE Invoice ( InvoiceID int NOT NULL, InvoiceNumber char(10) NOT NULL, CustomerName char(30) NOT NULL, InvoiceAmount money NOT NULL DEFAULT (0), CONSTRAINT PK_Invoice PRIMARY KEY (InvoiceID) )你想验证这些和平常不一样的订单的样品,为此,你必须为每个顾客生成一列货物,货物数量少于该顾客平均的货物数量. 你应该用哪个查询?

  • 单项选择题
  • SELECT i1.InvoiceNumber, i1.CustomerName, i1.InvoiceAmount FROM Invoice As i1, Invoice AS i2 GROUP BY i1.InvoiceNumber, i1.CustomerName, i1.InvoiceAmount HAVING i1.InvoiceAmount < AVG (i2.InvoiceAmount) ORDER BY i1.CustomerName, i1.InvoiceNumber
  • SELECT i1.InvoiceNumber, i1.CustomerName, i1.InvoiceAmount FROM Invoice As i1 WHERE i1.InvoiceAmount < (SELECT AVG (i2.InvoiceAmount) FROM Invoice AS i2 WHERE i2.CustomerName=i1.CustomerName) ORDER BY i1.CustomerName, i1.InvoiceNumber
  • SELECT i1.InvoiceNumber, i1.CustomerName, i1.InvoiceAmount FROM Invoice As i1 WHERE i1.InvoiceAmount < (SELECT AVG (i2.InvoiceAmount) FROM Invoice AS i2) ORDER BY i1.CustomerName, i1.InvoiceNumber
  • SELECT i1.InvoiceNumber, i1.CustomerName, i1.InvoiceAmount, CASE WHEN i1.InvoiceAmount < AVG (i2.InvoiceAmount) THEN i1.InvoiceAmount ELSE 0 END FROM Invoice As i1 INNER JOIN Invoice AS i2 ON i1.CustomerName = i2.CustomerName GROUP BY i1.InvoiceNumber, i1.CustomerName, i1.InvoiceAmount ORDER BY i1.CustomerName, i1.InvoiceNumber

  •          


    200题为1关,请收藏当前位置,方便下次学习。


    第1关   129   130   131   132   133   134   135   136   137   138   139   140   141   142   143   144   145   146   147   148   149   150   151   152   153   154   155   156   157   158   159   160   161   162   163   164   165   166   167   168   169   170   171   172   173   174   175   176   177   178   179   180   181   182   183   184   185   186   187   188   189   190   191   192   193   194   195   196   197   198   199   200   第2关   第3关  


    完整版《考试通关题库》请扫描下图二维码关注官方微信公众号,加入会员,即可打包下载!经广大会员朋友实战检验,使用本题库考试通过率大大提高!绝对是您考试通关的不二利器!