
Answer-first summary for fast verification
Answer: SELECT price(customer_spend, customer_units) AS customer_price FROM customer_summary
The correct answer is E because it properly calls the user-defined function 'price' with the correct column names 'customer_spend' and 'customer_units' as arguments, and aliases the result as 'customer_price'. This follows standard SQL syntax for calling UDFs. Option A incorrectly uses 'PRICE' as a keyword and has syntax errors. Option B is incomplete and malformed. Option C incorrectly wraps the function call with another 'function()' call. Option D incorrectly wraps the function call with 'double()', which is unnecessary since the function already returns DOUBLE. The community discussion with 100% consensus and 3 upvotes confirms E is correct, explaining that UDFs are called by name with appropriate column arguments in SELECT statements.
Author: LeetQuiz Editorial Team
Ultimate access to all questions.
No comments yet.
A data analyst has created a user-defined function using the following code:
CREATE FUNCTION price(spend DOUBLE, units DOUBLE)
RETURNS DOUBLE
RETURN spend / units;
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 customer_summary table to create a customer_price column?
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