Deal of The Day! Hurry Up, Grab the Special Discount - Save 25% - Ends In 00:00:00 Coupon code: SAVE25
Welcome to Pass4Success

- Free Preparation Discussions

Databricks Certified Data Analyst Associate Exam - Topic 3 Question 24 Discussion

Posted by Elroy on Sep 19, 2024 at 04:33 PM

A data analyst has been asked to use the below table sales_table to get the percentage rank of products within region by the sales:

The result of the query should look like this:

Which of the following queries will accomplish this task?

A)

B)

C)

Suggested Answer: B

The correct query to get the percentage rank of products within region by the sales is option B. This query uses the PERCENT_RANK() window function to calculate the relative rank of each product within each region based on the sales amount. The window function is partitioned by region and ordered by sales in descending order. The result is aliased as rank and displayed along with the region and product columns. The other options are incorrect because:

A) Option A uses the RANK() window function instead of the PERCENT_RANK() function. The RANK() function returns the rank of each row within the partition, but not the percentage rank. Also, the query does not have a GROUP BY clause, which is required for aggregate functions like SUM().

C) Option C uses the DENSE_RANK() window function instead of the PERCENT_RANK() function. The DENSE_RANK() function returns the rank of each row within the partition, but not the percentage rank. Also, the query does not have a GROUP BY clause, which is required for aggregate functions like SUM().

D) Option D uses the ROW_NUMBER() window function instead of the PERCENT_RANK() function. The ROW_NUMBER() function returns the sequential number of each row within the partition, but not the percentage rank. Also, the query does not have a GROUP BY clause, which is required for aggregate functions like SUM().Reference:

1: PERCENT_RANK (Transact-SQL)

2: Window functions in Databricks SQL

3: Databricks Certified Data Analyst Associate Exam Guide


Get Premium Databricks Certified Data Analyst Associate Questions as Interactive Web-Based Practice Test or PDF Real Exam Format Detailed Explanations Instant Access Get Your Practice Test
34 comments · newest first
KA
Kathryn 10 months ago
Just a heads up, percentage rank can be tricky in SQL!
BE
Belen 11 months ago
Definitely going with Option D, it makes the most sense!
LA
Lai 11 months ago
Wait, are we sure about Option C? It seems off.
AL
Aleisha 11 months ago
I think Option A might actually work too.
VA
Val 11 months ago
Option B looks like the right choice for percentage rank.
GA
Gaynell 12 months ago
I feel like option A could be correct, but I need to double-check how the partitioning works in that context.
KE
Keneth 12 months ago
I’m a bit confused about the syntax for the ranking function. Was it `PERCENT_RANK()` or something else?
CH
Chaya 12 months ago
I think option B looks familiar; it might be similar to a practice question we did last week.
JA
Janella 1 year ago
I remember we practiced calculating percentage ranks, but I’m not sure if it was specifically by region.
HE
Heike 1 year ago
I've seen similar problems before, so I think I've got a good strategy for this. I'll focus on using the right window function and making sure the ranking is calculated correctly within each region.
TI
Timmy 1 year ago
I'm a bit confused by the different options. I'll need to read through the question and the SQL queries more closely to understand what each one is doing.
EL
Eladia 1 year ago
Okay, let's break this down step-by-step. I'll need to use a window function to calculate the percentage rank within each region. I think Option B might be the way to go.
JO
Jolanda 1 year ago
Hmm, I'm not sure about this one. The percentage rank calculation seems a bit tricky. I'll need to think it through carefully.
DA
Dante 1 year ago
This looks like a pretty straightforward SQL problem. I think I can handle this one.
SH
Shoshana 1 year ago
Hmm, this seems like a tricky one. I'll need to think carefully about the different logging options and which one would be most helpful for diagnosing the slow behavior.
NA
Nana 2 years ago
Wait, where's the 'D) None of the above' option? You know, for those of us who just want to walk away from this whole thing.
DI
Dierdre 2 years ago
Option C? Really? That query looks like a hot mess. I'd rather not get my hands dirty with that one.
JU
Justine 2 years ago
↳ replying to Dierdre
I'm with you on that. Let's steer clear of Option C and find a better way to get the job done.
VI
Viki 2 years ago
↳ replying to Dierdre
Yeah, Option C looks like it would take forever to debug. I'd rather go with something more straightforward.
GL
Glen 2 years ago
↳ replying to Dierdre
I agree, Option C does seem overly complicated. I would prefer a simpler solution.
BR
Brice 2 years ago
I'm going with Option B. It's the most elegant solution and gets the job done without any unnecessary complexity.
TH
Thaddeus 2 years ago
↳ replying to Brice
Option B does look like the cleanest solution for this task. It's a good choice.
LE
Leanora 2 years ago
↳ replying to Brice
I agree, Option B seems like the most logical and efficient way to achieve the desired result.
AS
Asha 2 years ago
↳ replying to Brice
I think Option B is the best choice too. It's straightforward and efficient.
KI
Kip 2 years ago
Woah, hold up! Using a subquery just to get the percentage rank? That seems a bit overkill, don't you think?
HI
Hildegarde 2 years ago
Ah, I see what they're going for with the PERCENT_RANK() function. That should do the trick!
RO
Rosamond 2 years ago
You might be right, I overlooked that detail. Option C does seem to be the most appropriate choice for this task.
HA
Hana 2 years ago
This query looks straightforward, but I'm not sure if it's using the right window function. Hmm, let me think this through.
MA
Matthew 2 years ago
↳ replying to Hana
Option B looks like it could be the right one based on the window function used.
MI
Michel 2 years ago
↳ replying to Hana
Maybe option B would be a better choice.
JO
Josefa 2 years ago
↳ replying to Hana
I think option A might not be using the correct window function.
NO
Noe 2 years ago
↳ replying to Hana
Have you tried using option A?
VI
Vi 2 years ago
I disagree, I believe Option C is the right query as it uses the PERCENT_RANK() function which is specifically mentioned in the question.
RO
Rosamond 2 years ago
I think the correct query is Option A because it includes the RANK() function.
0/2000 characters

Save Cancel