Question

I have a data set filled with race drivers with a recording of each of their lap times for 10 laps. The request is to not show the lap times but just the rankings for each lap ( ex. Jeff Gordon Lap 1: 1st, Lap 2: 5th, Lap 3: 9th, Lap 4: 3rd, etc)

I have pgadmin, tableau and excel to get this done. Any sound direction would be much appreciated.

Was it helpful?

Solution

You didn't give us much detail about your tables, but something like:

select driver_name,
       lap_number, 
       dense_rank() over (partition by lap_number order by lap_time) as rank_in_lap,
       dense_rank() over (order by lap_time) as overall_rank
from lap_times
order by driver_name, lap_number;

More details about window functions are in the manual:

OTHER TIPS

Window functions are very useful as a_horse_with_no_name suggests. So much so that Tableau provides table calculation functions that pretty much follow the same design and function names -- allowing you to do the calculations on the server side via SQL or on the client side as a table calc depending on which is more convenient for you.

The Tableau functions to look at are rank(), rank_dense(), rank_modified(), rank_percentile() and rank_unique(). You also have set the "compute using" information for your calculations in Tableau, wich are the analogue for the "partition by" and "order by" clauses in the a SQL window function.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top