質問

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.

役に立ちましたか?

解決

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:

他のヒント

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.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top