OCP 071 某题解析

View the Exhibit and examine the structure of the ORDER_ITEMS table.

 

(Choose the best answer.)

 

You must select the ORDER_ID of the order that has the highest total value among all the orders in the ORDER_ITEMS table.

Which query would produce the desired result?
A. SELECT order_id

FROM order_items

GROUP BY order_id

HAVING SUM(unit_price*quantity) = (SELECT MAX (SUM(unit_price*quantity))

FROM order_items GROUP BY order_id);
B. SELECT order_id

FROM order_items

WHERE(unit_price*quantity) = (SELECT MAX (SUM(unit_price*quantity)

FROM order_items) GROUP BY order_id);

C. SELECT order_id

FROM order_items

WHERE(unit_price*quantity) = MAX(unit_price*quantity)

GROUP BY order_id);

D. SELECT order_id

FROM order_items

WHERE (unit_price*quantity) = (SELECT MAX(unit_price*quantity)

FROM order_items

GROUP BY order_id)

   




Answer: A

 

 Explanation/Reference:

语句分解

这题看着很费劲,,于是创建一个表,并录入随机数据,  注意是 随机数据 

0主干语句    是把  the highest total value among all the orders in the ORDER_ITEMS table    对应的order_id 选出来,,,注意关键词   有个“total”。。

因此第一步可以是先找出    the highest total value among all the orders in the ORDER_ITEMS table    的值。。

SELECT MAX (SUM(unit_price*quantity))

FROM order_items 

但注意,,由于有sum   这是个分组函数。。需要有group by  否则会报错。

下图是正确的表达方式

可以得出最大值是  125189。。

由于125189 这个数值是个聚合函数的值。

 

因此需要把 order_id做了分组  ,候选出三个order_id   ,

根据题意,从三个order_id 选出sum(unit_price*quantity)  最大的。。

于是下一步是   
 

 

 

得出题目要的答案。。。确认A选项是正确的。。

 

解析出A选项后再看其他选项就发现其他选项 主干 确失 group by 函数了。。均不符合题意。。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值