Databricks Certified Data Analyst Associate — Question 16
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?
Answer options
- A. SELECT PRICE customer_spend, customer_units AS customer_price FROM customer_summary
- B. SELECT price - FROM customer_summary
- C. SELECT function(price(customer_spend, customer_units)) AS customer_price FROM customer_summary
- D. SELECT double(price(customer_spend, customer_units)) AS customer_price FROM customer_summary
- E. SELECT price(customer_spend, customer_units) AS customer_price FROM customer_summary
Correct answer: E
Explanation
The correct answer is E because it correctly calls the user-defined function price with the appropriate parameters and assigns the result to the customer_price column. Options A and B are syntactically incorrect as they do not properly invoke the function or use the correct SQL syntax. Option C incorrectly applies the function keyword, and D incorrectly uses the double keyword, which is unnecessary.