Databricks Data Engineer Associate exam dumps

Databricks Data Engineer Associate practice question 192 of 532

Databricks Certified Data Engineer Associate. Associate level, Databricks. Free question with the correct answer and a full explanation.

Databricks Data Engineer Associate Question 192

Single answer

You have a table named sales_data with the following schema:

product_idregionsales
101North500
101South300
102North400
102South600

You want to transform this table to show regions as columns and their corresponding sales values, resulting in the following structure:

product_idNorthSouth
101500300
102400600

Which of the following SQL queries will achieve this transformation?

  1. A

    SELECT product_id, North, South FROM sales_data PIVOT (SUM(sales) FOR region IN ('North', 'South'))

  2. B

    SELECT product_id, North, South FROM sales_data PIVOT (SUM(sales) FOR region IN ('North' AS North, 'South' AS South))

  3. C

    SELECT product_id, North, South FROM (SELECT * FROM sales_data) PIVOT (SUM(sales) FOR region IN ('North', 'South'))

  4. D

    SELECT product_id, North, South FROM (SELECT * FROM sales_data) PIVOT (COUNT(sales) FOR region IN ('North', 'South'))

Show answer and explanation

Correct answer: C

Explanation

The correct query uses the PIVOT clause to transform the sales_data table from a long format to a wide format, with regions as columns and their corresponding sales values. In Databricks, the PIVOT clause must be applied to a subquery or table expression, and the aggregation function (e.g., SUM) must match the desired result.

  • A. Incorrect.

    This query incorrectly applies the PIVOT clause directly on the table without wrapping the base query in a subquery, which is not valid syntax in Databricks.

  • B. Incorrect.

    This query introduces invalid syntax by attempting to alias values in the IN clause, which is not supported in the PIVOT clause.

  • C. Correct.

    This query correctly applies the PIVOT clause on a subquery, aggregating sales values using SUM() for each region and transforming the data into the desired wide format.

  • D. Incorrect.

    This query incorrectly uses the COUNT() function instead of SUM(), which would result in counting the number of rows per region rather than summing the sales values.

Timed practice exam

Take a Databricks Data Engineer Associate practice test under exam conditions

45 questions in 90 minutes, drawn from this bank, with a score report and a per-question review when you finish.

Start timed exam