
Databricks Certified Data Engineer - Associate
Get started today
Ultimate access to all questions.
You are tasked with creating a table named employees
in Delta Lake with a calculated column age
derived from the dateOfBirth
column. The SQL code block provided is incomplete. Select the correct statement to fill in the blank for the SQL code to execute successfully.
You are tasked with creating a table named employees
in Delta Lake with a calculated column age
derived from the dateOfBirth
column. The SQL code block provided is incomplete. Select the correct statement to fill in the blank for the SQL code to execute successfully.
Explanation:
Delta Lake supports generated columns, which automatically compute their values based on a user-specified function over other columns in the Delta table. For the age
column to be correctly calculated from dateOfBirth
, the correct syntax is GENERATED ALWAYS AS (CAST(DATEDIFF(CURRENT_DATE, dateOfBirth) / 365) AS INT)
. This ensures the age is always computed as an integer based on the difference in days between the current date and the date of birth, divided by 365.