databricks Data Analyst Associate · Practice questions

Section 4: Executing Queries Using Databricks SQL and SQL Warehouses Practice Questions

Review 10 sample questions with their correct answers and explanations. Sign up free to continue with the full topic quiz.

Sign up free for the full quiz

Question 1

A sales table has columns region, product and revenue. An analyst wants totals by region and product, plus subtotals per region and a grand total, in one query. Which clause supports this?

  1. GROUP BY region UNION ALL product
  2. PARTITION BY region, product
  3. GROUP BY ROLLUP(region, product) — Correct
  4. GROUP BY region, product HAVING ALL

Correct answer

GROUP BY ROLLUP(region, product)

Explanation

ROLLUP produces hierarchical subtotals: (region, product), (region) and the grand total (). CUBE would also add product-only subtotals.

Question 2

An analyst's query returns zero rows: SELECT * FROM t WHERE region = NULL. What change returns rows with a missing region?

  1. WHERE region IS NULL — Correct
  2. WHERE NOT region
  3. WHERE region == NULL
  4. WHERE region = 'NULL'

Correct answer

WHERE region IS NULL

Explanation

Comparisons with NULL using = evaluate to NULL, which is treated as false. Use IS NULL. The string 'NULL' is a different value.

Question 3

An analyst must compute each month's revenue and the running total for the year. Which expression computes the running total?

  1. SUM(revenue) OVER (PARTITION BY year, month ORDER BY month ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING)
  2. CUMSUM(revenue) OVER year
  3. SUM(revenue) GROUP BY year, month
  4. SUM(revenue) OVER (PARTITION BY year ORDER BY month ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) — Correct

Correct answer

SUM(revenue) OVER (PARTITION BY year ORDER BY month ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW)

Explanation

A windowed SUM ordered by month with a frame from the start of the partition to the current row produces a cumulative total. Partitioning by month would give each month's total only.

Question 4

An analyst must store the result of a query as a managed table so that teammates can query it later. Which statement is correct?

  1. CREATE TEMPORARY VIEW results AS SELECT ...
  2. CACHE TABLE results AS SELECT ...
  3. SET results = SELECT ...
  4. CREATE TABLE main.team.results AS SELECT ... — Correct

Correct answer

CREATE TABLE main.team.results AS SELECT ...

Explanation

CTAS creates a persistent managed Delta table in the specified catalog and schema. Temporary views exist only in the current session.

Question 5

A team runs many short, unpredictable ad hoc queries during the day and wants the fastest startup time with no idle infrastructure to manage. Which SQL warehouse type is the best fit?

  1. Single-node all-purpose cluster
  2. Serverless — Correct
  3. Pro
  4. Classic

Correct answer

Serverless

Explanation

Serverless SQL warehouses start in seconds, scale quickly and run in Databricks-managed compute, which suits bursty ad hoc workloads. Classic and Pro warehouses run in the customer's account and start more slowly.

Question 6

A cleaning step must replace negative quantities with NULL in a silver table. Which expression is correct?

  1. COALESCE(quantity, 0)
  2. NULLIF(quantity < 0)
  3. CASE WHEN quantity < 0 THEN NULL ELSE quantity END — Correct
  4. IF(quantity < 0, 0, quantity) so negatives become zero

Correct answer

CASE WHEN quantity < 0 THEN NULL ELSE quantity END

Explanation

A CASE expression returns NULL for negative values and keeps other values. COALESCE replaces NULLs; it does not detect negatives.

Question 7

An analyst must delete invalid rows from a Unity Catalog table where amount is negative. Which statement is correct for a Delta table?

  1. TRUNCATE sales.silver.payments WHERE amount < 0
  2. ALTER TABLE sales.silver.payments DELETE amount < 0
  3. DROP ROWS FROM sales.silver.payments WHERE amount < 0
  4. DELETE FROM sales.silver.payments WHERE amount < 0 — Correct

Correct answer

DELETE FROM sales.silver.payments WHERE amount < 0

Explanation

Delta tables support DELETE FROM with a predicate. TRUNCATE removes all rows and does not accept a WHERE clause.

Question 8

A product catalog has a sub_category column with 'Laptops', 'laptops', and ' LAPTOPS ' for the same category. Which expression standardizes these values?

  1. trim(sub_category)
  2. lower(trim(sub_category)) — Correct
  3. initcap(sub_category)
  4. replace(sub_category, ' ', '')

Correct answer

lower(trim(sub_category))

Explanation

trim removes leading and trailing spaces and lower normalizes case, so all three values become 'laptops'. initcap would still keep the spaces in ' LAPTOPS '.

Question 9

A sales table has a nullable discount column. A report must treat missing discounts as zero when computing net price. Which expression is correct?

  1. price - NULLIF(discount, 0)
  2. price - COALESCE(discount, 0) — Correct
  3. price - discount
  4. price - IFNULL(price, discount)

Correct answer

price - COALESCE(discount, 0)

Explanation

COALESCE returns the first non-null argument, so missing discounts become 0. price - discount returns NULL when discount is NULL. NULLIF does the opposite: it turns 0 into NULL.

Question 10

An analyst wants mean, standard deviation, min, max and quartiles for numeric columns of a table in a notebook, with the least code. Which approach fits?

  1. Write a separate query for every statistic and column
  2. Use df.summary() or the notebook data profile — Correct
  3. Run OPTIMIZE and read the statistics from the output
  4. Run DESCRIBE HISTORY on the table

Correct answer

Use df.summary() or the notebook data profile

Explanation

DataFrame.summary() (and the notebook data profile) compute count, mean, stddev, min, quartiles and max. DESCRIBE HISTORY shows table versions.

Ready for the full quiz?

Create a free QuizAnalyst account to practice the complete question set and save your progress.

Sign up free for the full quiz