Press "Enter" to skip to content

Finding the Top Element in a Group via KQL

Dennes Torres is looking for the top dog:

When learning something new, we always compare it with what we know. In this case, we end up comparing KQL with SQL.

In SQL, when we need to get the top rows based on a grouping, the process is not easy. For example, let’s say that in a table containing taxi rides, we want to retrieve the record of the ride with the highest fare on each day.

There are multiple ways to do this, none is too easy. One of the methods is to create a row_number based on the day. This can be achieved using what’s called in SQL as window function. In this case row_number with a stablished window in the result based on the date.

Click through to see how you can use arg_max() in KQL to do this.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.