OCP-1Z0-051 第69题 ORDER BY 的null值排序

来源:互联网 发布:产品摄影 知乎 编辑:程序博客网 时间:2024/06/07 12:39
一、原题
You need to generate a list of all customer last names with their credit limits from the CUSTOMERS table. Those customers who do not have a credit limit should appear last in the list.
Which two queries would achieve the required result? (Choose two.)
A. SELECT cust_last_name, cust_credit_limit
       FROM customers
ORDER BY cust_credit_limit DESC ;

B. SELECT cust_last_name, cust_credit_limit
        FROM customers
ORDER BY cust_credit_limit;

C. SELECT cust_last_name, cust_credit_limit
        FROM customers
ORDER BY cust_credit_limit NULLS LAST;

D. SELECT cust_last_name, cust_credit_limit
        FROM customers
ORDER BY cust_last_name, cust_credit_limit NULLS LAST;

答案:BC
二、题目翻译
要根据CUSTOMERS表生成一个列表,显示客户的last name和他们的credit limits,那些没有credit limit的客户显示到列表的后面。(即null值放在最后)
哪两个查询能获取所需结果(选择两个正确的选项)
三、题目解析
A选项不正确,因为默认情况下,cust_credit_limit DESC降序排列后,空值会排列到前面。
B选项正确,默认升续排列,空值会排列到后面。
C选项正确,NULLS LAST关键字可以把空值排列到后面。
D选项不正确,因为排序条件不正确,先按名字排序了。
0 0