I’m trying to get the average of a ratio in SQL.
My table looks like this:
T_TOTAL | NUM_ASSETS
----------------------
32 | 8
20 | 4
24 | 4
And so that value I’m after is 5 as in:
T_TOTAL | NUM_ASSETS | T_TOTAL/NUM_ASSETS
---------------------------------------------
32 | 8 | 4
20 | 4 | 5
24 | 4 | 6
-------------------
AVG = 5
So far I have this but it’s not working:
SELECT T_TOTAL As Time, NUM_ASSETS As Assets,
Time/Assets As TimePerAsset, AVG(TimePerAsset) As Result
FROM MATCHES
Any ideas?
And if you have 0 in num_assets, you can avoid a division by 0 like this: