• 2 Posts
  • 85 Comments
Joined 1 year ago
cake
Cake day: June 18th, 2023

help-circle
















  • Yeah, I guess it’s a less-used analytic function (function? I think that’s the right term here).

    I believe this will only accept DENSE_RANK as the ranking part of this method, which makes sense cause you want a distinct list of ranks to identify the last one. You are right though that it’s possible for the record returned by the MAX() to be arbitrary if there are duplicate values in the ORDER BY field. Luckily you can usually handle for that by using multiple fields in the ORDER BY. The conditions in the query that the function operates on top of also play a roll. You can also include a PARTITION BY, but I’ve only needed to use that a time or two.

    I think one reason I like this more is it’s more readable to me. For a lot of the other analytic functions you end up using partitions and additional keywords like “ROWS BETWEEN UNBOUNDED AND …etc.” in order to break out results the way you need. With this dense_rank method I typically accomplish that using regular 'ole WHERE conditions. Of course that’s gonna be pretty subjective.

    Replying on in my phone now so limited in how detailed I can be. I can give better examples later if that doesn’t make sense.

    Edit: I think it is an Oracle thing. Analytics are one of the areas I will unapologetically use DB-specific functions. Portability be damned! Generally they’ve been tuned very specifically to solve a problem with the specific engine in mind. Of course that won’t always be true, but that’s my general thought process.