您的位置:首页 > 其它

OCP-1Z0-051 第118题 GROUP BY,HAVING子句

2014-05-13 08:49 399 查看
一、原题

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



Examine the following two SQL statements:

Statement 1

SQL>SELECT promo_category,SUM(promo_cost)   

            FROM promotions   

          WHERE promo_end_date-promo_begin_date > 30   

    GROUP BY promo_category;

Statement 2

SQL>SELECT promo_category,sum(promo_cost)    

            FROM promotions   

    GROUP BY promo_category   

         HAVING MIN(promo_end_date-promo_begin_date)>30;

Which statement is true regarding the above two SQL statements?

A. statement 1 gives an error, statement 2 executes successfully

B. statement 2 gives an error, statement 1 executes successfully

C. statement 1 and statement 2 execute successfully and give the same output
D. statement 1 and statement 2 execute successfully and give a different output

答案:D

二、题目翻译

查看PROMOTIONS表的结构

评估下面的2个语句

关于上面两个SQL语句,哪句话是正确的?

A.语句1报错,语句2执行成功。

B.语句2报错,语句1执行成功。

C.都执行成功,并给出相同结果。

D.都执行成功,但给出不同的结果。

三、题目解析

      WHERE是分组之前筛选数据,HAVING是分组之后筛选数据,所以结果是不一样的。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息