OCP-1Z0-051-V9 02-64题

               
64. View the E xhibit and examine the data in the PROMO_CATEGORY and PROMO_COST columns of
the PROMOTIONS table.
Evaluate the following two queries:
SQL>SELECT DISTINCT promo_category   to_char(promo_cost)"code"    
FROM promotions    
ORDER BY code;
SQL>SELECT DISTINCT promo_category  promo_cost "code"    
FROM promotions    
ORDER BY 1;
Which statement is true regarding the execution of the above queries? 
A. Only the first query executes successfully.
B. Only the second query executes successfully.
C. Both queries execute successfully but give different results.
D. Both queries execute successfully and give the same result.
Answer: B
答案解析:
order by 可以指定 表达式、别名或列位置作为排序条件,别名要完全匹配
列别名并没有完全匹配,所以报错。

sh@TEST0924>  SELECT DISTINCT promo_category, to_char(promo_cost)"code"

  2  FROM promotions

  3  ORDER BY code;

ORDER BY code

         *

ERROR at line 3:

ORA-00904: "CODE": invalid identifier

 应该改为:

sh@TESTDB> SELECT DISTINCT promo_category, to_char(promo_cost)"code"
  2  FROM promotions
  3  where rownum<6
  4   ORDER BY "code";
 
PROMO_CATEGORY                 code
------------------------------ ----------------------------------------
NO PROMOTION                   0
newspaper                      200
post                           300
newspaper                      400
internet                       600

 第二个SQL如下,可执行成功,原题差一个逗号

sh@TESTDB> SELECT DISTINCT promo_category,promo_cost "code"
  2  FROM promotions
  3  where rownum<6
  4   ORDER BY 1;
 
PROMO_CATEGORY                       code
------------------------------ ----------
NO PROMOTION                            0
internet                              600
newspaper                             200
newspaper                             400
post                                  300
           

再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://blog.csdn.net/jiangjunshow

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值