Reputation: 1831
I have a table just like this:
| id | totalScore |
--------------------------
| 1 | -3 |
| 2 | 6 |
| 3 | 10 |
| 4 | 7 |
| 5 | -4 |
| 6 | 4 |
| 7 | -3 |
...
So for a given number (example 5), I want to find * You're better than 10% of users! *, or 20%, or 30%, etc.
How can I do this? Maybe using average
of totalScore
column and group by
10, 20, 30 values? Is it possible?
I'm using Laravel 5.6.
Upvotes: 1
Views: 65
Reputation: 3855
E.g. you'll have a user with score 5.
You have a total of 7 users out of which 4 have a lower score than 5, resulting in
4/7*100 = 57%
Upvotes: 4