CertLumen

Databricks Data Analyst Associate · Section 4 · 20% of the exam

Perform sorting and filtering operations on a table.

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) and count(DISTINCT col) skip NULLs.
  • approx_count_distinct uses 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, max and median ignore NULLs; an all-NULL group returns NULL; avg(coalesce(x, 0)) treats missing values as zero.
  • median is exact; percentile_approx (default accuracy 10000) is approximate; stddev is 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?

  1. Acount(*) AS orders, count(amount >= 100) AS big_orders
  2. Bcount(*) AS orders, count_if(amount >= 100) AS big_orders
  3. Ccount(*) AS orders, count(DISTINCT amount >= 100) AS big_orders
  4. Dcount(*) 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

← Previous objective · All 39 objectives · Next objective →