一、原题
二、题目翻译
三、题目解析
Examine the data in the ORD_ITEMS table:
ORD_NO ITEM_NO QTY
1 111 10
1 222 20
1 333 30
2 333 30
2 444 40
3 111 40
You want to find out if there is any item in the table for which the average maximum quantity is more than 50.
You issue the following query:
SQL> SELECT AVG(MAX(qty))
FROM ord_items
GROUP BY item_no
HAVING AVG(MAX(qty))>50;
Which statement is true regarding the outcome of this query?
A. It executes successfully and gives the correct output.
B. It gives an error because the HAVING clause is not valid.
C. It executes successfully but does not give the correct output.
D. It gives an error because the GROUP BY expression is not valid.
答案:B
ORD_NO ITEM_NO QTY
1 111 10
1 222 20
1 333 30
2 333 30
2 444 40
3 111 40
You want to find out if there is any item in the table for which the average maximum quantity is more than 50.
You issue the following query:
SQL> SELECT AVG(MAX(qty))
FROM ord_items
GROUP BY item_no
HAVING AVG(MAX(qty))>50;
Which statement is true regarding the outcome of this query?
A. It executes successfully and gives the correct output.
B. It gives an error because the HAVING clause is not valid.
C. It executes successfully but does not give the correct output.
D. It gives an error because the GROUP BY expression is not valid.
答案:B
二、题目翻译
查看ORD_ITEMS表的数据
要找到表中任意item的最大值的平均值是否大于50
执行下面的查询:
关于查询结果,下面描述正确的是?
A.执行成功并给出正确结果。
B.报错,因为HAVING子句是无效的。
C.执行成功,但是不能给出正确结果。
D.报错,因为GROUP BY表达式无效。
要找到表中任意item的最大值的平均值是否大于50
执行下面的查询:
关于查询结果,下面描述正确的是?
A.执行成功并给出正确结果。
B.报错,因为HAVING子句是无效的。
C.执行成功,但是不能给出正确结果。
D.报错,因为GROUP BY表达式无效。
三、题目解析
HAVING子句后面嵌套了2个组函数,只能使用一个组函数,而且,已经是最大值了,只有一个值,再求平均值,完全没意义。
该博客讨论了一道OCP-1Z0-051考试中的题目,涉及GROUP BY和HAVING子句在查询中的应用。题目要求找出ORD_ITEMS表中平均最大数量超过50的项,但给出的查询语句由于在HAVING子句中错误地嵌套了两个聚合函数,导致错误。解释指出,HAVING子句中只能使用一个组函数,并且在已计算出最大值的情况下再求平均值是没有意义的。
2907

被折叠的 条评论
为什么被折叠?



