Home / Data Analyst practice test / Analyzing Queries / Question

Databricks Data Analyst Associate · free practice question

A data analyst writes the following query to find customers who have made at least one purchase in 2025: SELECT customer_id FROM orders WHERE year = 2025 GROUP…

Exam-style question on Analyzing Queries from the free Data Analyst practice test, with the answer and a full explanation below.

Updated November 10, 2026

Analyzing Queries

A data analyst writes the following query to find customers who have made at least one purchase in 2025:

SELECT customer_id FROM orders WHERE year = 2025 GROUP BY customer_id HAVING COUNT(*) >= 1;

The query runs but returns far fewer customers than expected. After investigation, the analyst finds the orders table has a column named 'purchase_year' (not 'year'). The WHERE clause references a non-existent column. How should the query be fixed?

  1. AAdd an alias: SELECT customer_id FROM orders WHERE year AS purchase_year = 2025 GROUP BY customer_id HAVING COUNT(*) >= 1 — using AS in the WHERE clause allows the engine to resolve the column name at filter time without changing the schema
  2. BAdd a table alias and qualify the column: SELECT customer_id FROM orders o WHERE o.year = 2025 GROUP BY customer_id HAVING COUNT(*) >= 1 — qualifying the column name with the table alias resolves column name ambiguity in tables that have multiple columns with similar names
  3. CRemove the WHERE clause entirely and change the HAVING clause to HAVING purchase_year = 2025 AND COUNT(*) >= 1, because HAVING is evaluated after GROUP BY and can apply both aggregate and non-aggregate conditions including column-level filters like the year
  4. DUse a CASE expression: SELECT customer_id FROM orders WHERE CASE WHEN year IS NULL THEN purchase_year END = 2025 GROUP BY customer_id HAVING COUNT(*) >= 1 — this safely handles the possibility that the column is named 'year' in some partitions and 'purchase_year' in others
  5. EReplace 'year' with the correct column name: SELECT customer_id FROM orders WHERE purchase_year = 2025 GROUP BY customer_id HAVING COUNT(*) >= 1 — this corrects the filter and returns all customers with at least one 2025 order
Answer & explanation

Correct answer: E

WHY E: The root cause is a misspelled column name in the WHERE clause (year instead of purchase_year). The correct fix is straightforward — replace 'year' with 'purchase_year' to reference the actual column. The rest of the query logic (GROUP BY + HAVING COUNT(*) >= 1) is correct. WHY NOT A: SQL does not support AS aliases inside WHERE clauses to rename column references; this syntax is invalid. WHY NOT C: Moving the column filter to HAVING is technically possible but non-standard, less efficient (filters all rows through GROUP BY before applying the year condition), and doesn't fix the root cause of referencing the wrong column name. WHY NOT D: The table has one fixed schema; CASE WHEN to handle different column names in different partitions is not valid for this scenario and would not resolve the misspelling. WHY NOT B: A table alias qualifies the column but does not rename it; o.year still references a non-existent column and would still fail.

Take the full Data Analyst practice test free →

Would you pass today?

This question is one of 45 in the free, timed Databricks Data Analyst Associate practice test. Take it and get a section-by-section score.

Start the free test →