nerdexam
SnowflakeSnowflake

SOL-C01 · Question #88

SOL-C01 Question #88: Real Exam Question with Answer & Explanation

The correct answer is E: Option E. Option E correctly uses the window function to assign a rank to each product within each region based on their total sales amount. The `PARTITION BY clause ensures that the ranking is done separately for each region. The 'QUALIFY clause filters the results to include only the top

Querying and Performance

Question

You have a table named 'PRODUCT SALES' with columns 'product id', 'sale date', 'region', and 'sales_amount'. You need to create a query that returns the top 3 products by total sales amount for each region. Which of the following SQL queries using window functions correctly implements this requirement?

Options

  • AOption A
  • BOption B
  • COption C
  • DOption D
  • EOption E

Explanation

Option E correctly uses the window function to assign a rank to each product within each region based on their total sales amount. The `PARTITION BY clause ensures that the ranking is done separately for each region. The 'QUALIFY clause filters the results to include only the top 3 products for each region based on the calculated rank. 'DENSE_RANK ensures continuous ranking without gaps even with tie sales amounts within each region. Option A does not work because QUALIFY cannot be used on an alias within the same subquery that creates it. Options B and D do not correctly partition results by the region. Option C cannot include window functions in HAVING clause, as it is incorrect sql syntax.

Topics

#Window Functions#Ranking Functions#SQL Aggregation#CTEs

Community Discussion

No community discussion yet for this question.

Full SOL-C01 PracticeBrowse All SOL-C01 Questions