DATABRICKS-DATA-ENGINEER-ASSOCIATE practice question 24 of 25

Which of the following SQL keywords can be used to convert a table from a long format to a wide format?

Full set: 177 questions
Answer options
A: PIVOT Correct answer
B: CONVERT
C: WHERE
D: TRANSFORM
E: SUM
Correct Answer:
A. PIVOT
Explanation

The PIVOT clause in Databricks SQL is used to transform a table expression from a long format to a wide format. It rotates a table by turning the unique values from a specified pivot column into separate columns in the output. An aggregate function is then used to compute the values for these newly created columns. This operation is fundamental for creating summary tables or cross-tabulations, which represent data in a wide, more human-readable format.

Why Incorrect

B. CONVERT: This function is used for changing the data type of a value from one type to another (e.g., string to integer), not for reshaping the structure of a table.
C. WHERE: This clause is used to filter rows from a result set based on a specified condition. It reduces the number of rows but does not alter the table's column structure.
D. TRANSFORM: In Databricks SQL, TRANSFORM is a higher-order function used to apply an expression to each element in an array, not to pivot a table from long to wide format.
E. SUM: This is an aggregate function used to calculate the total of a set of values. While it is often used within a PIVOT clause to aggregate data, it is not the keyword that performs the structural transformation. ---

References

1. Databricks SQL Language Reference

PIVOT clause: "The PIVOT clause is used for data perspective

you can get the aggregated values with a limited number of columns in a pivot table... The pivotclause rotates a table by turning the unique values from one column in the expression into separate columns."

2. Databricks SQL Language Reference

WHERE clause: "Filters the result of the FROM clause based on the supplied predicate."

3. Databricks SQL Language Reference

sum aggregate function: "Returns the sum calculated from values of a group."

4. Databricks SQL Language Reference

transform function: "Transforms elements in an array in expr using the function func."

5. Databricks SQL Language Reference

cast expression: "Casts the value expr to the data type targetType." (Note: CAST is the standard for type conversion

similar in function to CONVERT in other SQL dialects).

Scroll to Top