CERTIFIED-DATA-ANALYST-ASSOCIATE · Question #85
A data analyst is working with a nested array column products in table transactions. The analyst wants to return the first item in the array for each row. The data analyst is using the following…
The correct answer is C. products[0]. Option C (products[0]) is correct because arrays in most query languages (BigQuery, Python, JavaScript, etc.) use zero-based indexing, meaning the first element is at index 0, accessed with bracket notation [0]. Why the distractors are wrong: A (products.1) - Dot notation with…
Question
A data analyst is working with a nested array column products in table transactions. The analyst wants to return the first item in the array for each row. The data analyst is using the following incomplete command:
Which lines of code should the data analyst use to fill in the blank in the above code block so that it successfully completes the task?
Options
- Aproducts.1
- Cproducts[0]
- Dproducts[1]
How the community answered
(53 responses)- A15% (8)
- C79% (42)
- D6% (3)
Explanation
Option C (products[0]) is correct because arrays in most query languages (BigQuery, Python, JavaScript, etc.) use zero-based indexing, meaning the first element is at index 0, accessed with bracket notation [0].
Why the distractors are wrong:
- A (
products.1) - Dot notation with a number is not valid syntax for array indexing in SQL or most data platforms; dot notation is used for struct/object fields, not array positions. - D (
products[1]) - This accesses the second element (index 1), not the first, due to zero-based indexing.
Memory tip: Think of arrays like numbered floors in a building where the ground floor is Floor 0 - the first floor you enter is index [0], not [1]. "Zero is where you begin."
Community Discussion
No community discussion yet for this question.