
Answer-first summary for fast verification
Answer: EXPLODE
The correct answer is **EXPLODE**. This table-valued function takes an array or map and returns a row for each element in the array. For example, executing `select explode(orderIds) orderId, orderdate from orders` would produce a result set with a row for each element in the array, such as: OrderDate orderId 10-10-2021 100 10-10-2021 101 10-10-2021 102 ... This functionality is essential for transforming array elements into a format that can be joined with other tables, as required in the given query.
Author: LeetQuiz Editorial Team
Ultimate access to all questions.
No comments yet.
The sales team requests a report detailing the number of units sold by date. Given the schema below, which array function correctly fills in the blank to generate the desired report?
Table orders: orderDate DATE, orderIds ARRAY Table orderDetail: orderId INT, unitsSold INT, salesAmt DOUBLE
SELECT orderDate, SUM(unitsSold)
FROM orderDetail od
JOIN (select orderDate, ___________(orderIds) as orderId FROM orders) o
ON o.orderId = od.orderId
GROUP BY orderDate
SELECT orderDate, SUM(unitsSold)
FROM orderDetail od
JOIN (select orderDate, ___________(orderIds) as orderId FROM orders) o
ON o.orderId = od.orderId
GROUP BY orderDate
A
FLATTEN
B
EXTEND
C
EXPLODE
D
EXTRACT
E
ARRAY_FLATTEN