Skip to content
Advertisement

How can I add a Count with a condition from another table to a column/equation?

I currently have a table that calculates some player stats

Results

I am looking to also add the stat “Overall average % of field beaten”, but I am not sure how. The relevant columns in “EventResults” table are ‘EventID’, ‘PlayerID’ and ‘Position’

Image of EventResult table

The equation would be

But I can’t wrap my head around how to get that into a column.

Advertisement

Answer

As I mentioned in the comments, you need to use analytical function to figure this out correctly. This query should calculate the average percent of field beaten for each player:

As you may have noticed, I changed your formula a bit. I took the total number of participants subtracted by the position plus 1 (The plus 1 is to take the player out of the field) and divided it by the total number of participants. Lets say you win a tournament of 100 people the formula would be (100-1+1)/100 resulting in 1. Thus you beat 100% of the field.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement