A data engineer queries sales data in Amazon S3 using Amazon Athena. The query to sum sales by product for 2023 does not return results for all products. The original query is: SELECT product_name, sum(sales_amount) FROM sales_data - WHERE year = 2023 - GROUP BY product_name - How should the engineer change the Athena query to obtain the correct results?
Choose an answer
Tap an option to check your answer.
Correct answer: Change WHERE year = 2023 to WHERE extract(year FROM sales_data) = 2023..
Why this is the answer
The correct answer is to change WHERE year = 2023 to WHERE extract(year FROM salesdata) = 2023. The original query assumes a column named year exists and contains the year as an integer. If the salesdata column contains a full timestamp or date string, directly comparing year = 2023 will not work. The extract(year FROM salesdata) function correctly extracts the year component from a date or timestamp column, allowing for accurate filtering. Replacing sum(salesamount) with count() would change the aggregation to count records, not sum sales. Adding HAVING sum(salesamount) 0 would filter out products with zero or negative total sales, which might not be the desired outcome if all products should be included. Removing the GROUP BY clause would result in a single sum of all sales for 2023, not a sum by product.
Pass your exam — without the endless answer hunt
Get every verified question and explanation for this exam in one place, and save hours of prep. 1,000+ certifications · 20+ languages · free to start.
Pass your exam faster → No card needed