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?
- GROUP BY region UNION ALL product
- PARTITION BY region, product
- GROUP BY ROLLUP(region, product) — Correct
- 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?
- WHERE region IS NULL — Correct
- WHERE NOT region
- WHERE region == NULL
- 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?
- SUM(revenue) OVER (PARTITION BY year, month ORDER BY month ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING)
- CUMSUM(revenue) OVER year
- SUM(revenue) GROUP BY year, month
- 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?
- CREATE TEMPORARY VIEW results AS SELECT ...
- CACHE TABLE results AS SELECT ...
- SET results = SELECT ...
- 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?
- Single-node all-purpose cluster
- Serverless — Correct
- Pro
- 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?
- COALESCE(quantity, 0)
- NULLIF(quantity < 0)
- CASE WHEN quantity < 0 THEN NULL ELSE quantity END — Correct
- 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?
- TRUNCATE sales.silver.payments WHERE amount < 0
- ALTER TABLE sales.silver.payments DELETE amount < 0
- DROP ROWS FROM sales.silver.payments WHERE amount < 0
- 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?
- trim(sub_category)
- lower(trim(sub_category)) — Correct
- initcap(sub_category)
- 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?
- price - NULLIF(discount, 0)
- price - COALESCE(discount, 0) — Correct
- price - discount
- 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?
- Write a separate query for every statistic and column
- Use df.summary() or the notebook data profile — Correct
- Run OPTIMIZE and read the statistics from the output
- 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.