QuestionQ102

VerifiedExecuting queries using Databricks SQL and Databricks SQL Warehouses

A data analyst needs to use the following sales_table to rank products within each region by sales:

Question Image

The query result should appear as follows:

Question Image

Which query accomplishes this task?

Explanation

PARTITION BY region creates a separate ranking group for each region, while ORDER BY sales DESC gives the product with the greatest sales rank 1 within that region. RANK() assigns ranks according to the ordering in its window partition.

Learn more

Community Discussion

No comments yet. Be the first to start the discussion!