15. View the Exhibit and examine the data in the CUSTOMERS table.
Evaluate the following query:
SQL> SELECT cust_name AS "NAME", cust_credit_limit/2 AS MIDPOINT,MIDPOINT+100 AS "MAX
LOWER LIMIT"
FROM customers;
The above query produces an error on execution.
What is the reason for the error?
A. An alias cannot be used in an expression.
B. The a lias NAME should not be enclosed with in double quotation marks .
C. The MIDPOINT+100 expression gives an error because CUST_CREDIT_LIMIT contains NULL
values.
D. The a lias MIDPOINT should be enclosed with in double quotation marks for the
CUST_CREDIT_LIMIT/2 expression .
别名不能在同一范围内被另一列引用。
正确的写法应该是嵌套一层
SQL> show user;
User is "test"
SQL>
SQL> CREATE TABLE customers(cust_no,cust_name,cust_city,cust_credit_limit) AS
2 SELECT 101,'KING','NEW_YORK',100000 FROM DUAL UNION ALL
3 SELECT 102,'GREEN','BOSTON',150000 FROM DUAL UNION ALL
4 SELECT 103,'SCOTT','LONDON',NULL FROM DUAL UNION ALL
5 SELECT 104,'SMITH','BOSTON',NULL FROM DUAL;
Table created
SQL> SELECT "NAME",MIDPOINT,MIDPOINT+100 AS "MAX
2 LOWER LIMIT"
3 FROM
4 (
5 SELECT cust_name AS "NAME", cust_credit_limit/2 AS MIDPOINT
6 FROM customers);
NAME MIDPOINT MAX
LOWER LIMIT
----- ---------- ---------------
KING 50000 50100
GREEN 75000 75100
SCOTT
SMITH
Answer: A