14. Using the CUSTOMERS table, you need to generate a report that shows 50% of each credit
amount in each income level. The report should NOT show any repeated credit amounts in each income level.
Which query would give the required result?
(題意:使用客戶表,需要做一個報表,列出每個收入等級的信用額度的50%,並去除重複值。下面的哪個查詢語句可以得到這個結果?)
A.
SELECT cust_income_level, DISTINCT cust_credit_limit * 0.50
AS "50% Credit Limit"
FROM customers;
B.
SELECT DISTINCT cust_income_level, DISTINCT cust_credit_limit * 0.50
AS "50% Credit Limit"
FROM customers;
C.
SELECT DISTINCT cust_income_level ' ' cust_credit_limit * 0.50
AS "50% Credit Limit"
FROM customers;
D.
SELECT cust_income_level ' ' cust_credit_limit * 0.50
AS "50% Credit Limit"
FROM customers;
Answer: C
題目解析:
這道題是關於distinct的用法:
1.distinct只能放在第一個欄位的前面,如Select distinct x,y from t,
2.當distinct後有多個欄位時,表示所有欄位的值都相同才視為重複值,如Select distinct x,y from t,
只有當x,y的值都相同時,才視為重複值去除。
所以選項AB是語法錯誤,選項D沒有去除重複值,不合題意。
其實C也有點錯誤,正確的寫法是:
SELECT DISTINCT cust_income_level || cust_credit_limit * 0.50 AS "50% Credit Limit" FROM customers;
語句中的''應該換成串連符||