• 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
  • 相关阅读:
    c# 如何制作RealPlayer 视频播放器
    【.Net】在C#中判断某个类是否实现了某个接口
    【EF】Entity Framework 6新特性:全局性地自定义Code First约定
    【EF】EF实现大批量数据库插入操作
    【数据库】各种主流 SQLServer 迁移到 MySQL 工具对比
    【Python】python学习之总结
    【Asp.Net Core】ASP.NET Core 2.0 + EF6 + Linux +MySql混搭
    【.Net】Visual Studio的调试技巧
    【转载】用C#编写一个简单的记事本
    【ADO.NET】ADO.NET知识点
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13316907.html
Copyright © 2020-2023  润新知