CERTIFIED-DATA-ANALYST-ASSOCIATE · Question #11
CERTIFIED-DATA-ANALYST-ASSOCIATE Question #11: Real Exam Question with Answer & Explanation
The correct answer is E: SELECT price(customer_spend, customer_units) AS customer_price FROM customer_summary. Option E correctly invokes the UDF using standard SQL function-call syntax: price(customer_spend, customer_units) passes the two required DOUBLE arguments, AS customer_price aliases the result, and FROM customer_summary specifies the source table - matching exactly how the functi
Question
A data analyst has created a user-defined function using the following line of code: CREATE FUNCTION price(spend DOUBLE, units DOUBLE) RETURNS DOUBLE RETURN spend / units; Which of the following code blocks can be used to apply this function to the customer_spend and customer_units columns of the table customer_summary to create column customer_price?
Options
- ASELECT PRICE customer_spend, customer_units AS customer_price FROM customer_summary
- BSELECT price FROM customer_summary
- CSELECT function(price(customer_spend, customer_units)) AS customer_price FROM
- DSELECT double(price(customer_spend, customer_units)) AS customer_price FROM
- ESELECT price(customer_spend, customer_units) AS customer_price FROM customer_summary
Explanation
Option E correctly invokes the UDF using standard SQL function-call syntax: price(customer_spend, customer_units) passes the two required DOUBLE arguments, AS customer_price aliases the result, and FROM customer_summary specifies the source table - matching exactly how the function was defined.
Why the distractors fail:
- A treats
PRICEas a column name rather than calling it as a function, and the syntaxPRICE customer_spend, customer_unitsis malformed. - B references
priceas if it were a plain column in the table, with no arguments - UDFs require argument lists. - C wraps the call in
function(...), which is not valid SQL syntax; there is nofunction()wrapper in SQL. - D wraps the call in
double(...), which is not a valid SQL function;DOUBLEis a data type, not a callable wrapper.
Memory tip: Call a UDF exactly like a built-in SQL function - functionName(arg1, arg2) - no wrappers, no type names, just the function name followed by its arguments in parentheses. If it was defined with parameters, you must supply them.
Community Discussion
No community discussion yet for this question.