Databricks Data Analyst Associate · Section 4 · 20% of the exam
Perform aggregate operations such as count, approximate count distinct, mean, and summary statistics.
One of the objectives of the Databricks Certified Data Analyst Associate exam, in the section “Executing queries using Databricks SQL and Databricks SQL Warehouses”. Here is what it covers, the points to remember and a question to try.
What it covers
Aggregates turn rows into numbers, and filters and sorts decide which rows you see and in what order. This lesson covers the count family, approx_count_distinct, mean, median, percentiles and spread, GROUP BY with HAVING and ROLLUP, quick summary statistics in notebooks and the SQL editor, NULL-aware filtering, QUALIFY, and ORDER BY with LIMIT and OFFSET.
Points to remember
- Logical order: FROM/JOIN, WHERE, GROUP BY, HAVING, SELECT and window functions, QUALIFY, ORDER BY, LIMIT/OFFSET.
count(*)counts rows;count(col)andcount(DISTINCT col)skip NULLs.approx_count_distinctuses HyperLogLog++, returns a BIGINT and has a default relativeSD of 0.05 (5%); use it at scale for dashboards, not for audited numbers.avg/mean,sum,min,maxandmedianignore NULLs; an all-NULL group returns NULL;avg(coalesce(x, 0))treats missing values as zero.medianis exact;percentile_approx(default accuracy 10000) is approximate;stddevis the sample standard deviation.
Try a question
An analyst needs, in a single query over workspace.sales.orders, the total number of orders and the number of orders whose amount is at least 100. Which SELECT list returns both values correctly?
- A
count(*) AS orders, count(amount >= 100) AS big_orders - B
count(*) AS orders, count_if(amount >= 100) AS big_orders - C
count(*) AS orders, count(DISTINCT amount >= 100) AS big_orders - D
count(*) AS orders, max(amount >= 100) AS big_orders
Show the answer
B. count_if(cond) counts the rows for which the condition is true; rows where it is false or NULL aren't counted. count(expr) counts every non-NULL value, and a Boolean comparison is non-NULL whether it is true or false, so it can't count only the true ones. count(*) FILTER (WHERE amount >= 100) is another correct way to write it.
Written for practice in the style of the exam: never a question from the real exam.
In the course
The lesson Aggregations, Sorting and Filtering teaches this objective (about 45 minutes), and 13 practice questions test it. The course has lessons, exam-style questions, timed practice exams and an AI tutor for every objective, and a pass prediction that tells you when you're ready to book.
More in this section
- Utilize Databricks Assistant within a Notebook or SQL Editor to facilitate query writing and debugging.
- Explain the role a SQL Warehouse plays in query execution.
- Querying cross-system analytics by joining data from a Delta table and a federated data source.
- Create a materialized view, including knowing when to use Streaming Tables and Materialized Views, and differentiate between dynamic and materialized views.
- Write queries to combine tables using various join operations (inner, left, right, and so on) with single or multiple keys, as well as set operations like union and union all, including the differences between the joins (inner, left, right, and so on).
- Perform sorting and filtering operations on a table.
- Create managed tables and external tables, including creating tables by joining data from multiple sources (e.g., CSV, Parquet, Delta tables) to create unified datasets, including Unity Catalog.
- Use Delta Lake's time travel to access and query historical data versions.