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

本文通过两个具体的SQL查询案例,分析了WHERE子句与HAVING子句的区别及其对查询结果的影响。指出两者虽然都能实现条件过滤,但作用时机不同,导致最终输出结果存在差异。
118.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
解析:首先应该确定1和2执行都是正确的,1的条件在where中,是在group by之前进行过滤行
2的条件是在having中,是在group by之后进行过滤的,因此他们不一样
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值