Based on in that comment that better clarified the goal to be achieved, I leave as a reference this another answer , also mine.
Your problem seems to be more about mathematical logic than about implementation itself. It's simple, just a cross-multiplication.
Based on the response left as a reference, we have the logic:
A --- B
C --- D
Placing the sketch above in a mathematical formula, we have:
D = BC / A
Being:
-
A total uploaded files
-
B the total percentage (always 100)
-
C total uploaded files per user
-
D the value of the equation you need to find out
Assuming that one month 500 files have been uploaded and User X has sent 337, we have:
D = ( 100 * 337 ) / 500
D = 33700 / 500
D = 67,4%
That is, 67.4% of all files uploaded to the site.
The second part of your problem, also covered in the reference stack is to run this in batch, through a user function.
However, unlike the scenario you mentioned, you may not want to display this percentage individually, so in that case you create an array with all percentages and then sort . It would look something like this:
$percentual = array();
while( /** Faz a leitura do recurso vindo do banco */ ) {
$percentual[ $userID ] = getPercentage( $userUploads, $filesUploaded )
}
sort( $percentuals);
print_r( $percentuals );
function getPercentage( $total, $uploads ) {
return round( ( 100 * $uploads ) / $total );
}
The way the feature is read varies depending on the DBMS and the connection method used
In the example above:
-
$ userID is the user ID, but you can replace it with your user name and have an associative array ready for display.
-
$ userUploads is the total of files uploaded by the user. It may come from a COUNT () used in your SQL
-
$ filesUploaded is the total number of uploads made. It can come from a previously executed query or adding up each COUNT above. In this case, however, you may need to break the routine into two loops.
The output could be something like:
Array (
[X] => 67.4
[Y] => 16.3
[Z] => 16.3
)
That is, X was responsible for 67.4% of submissions while the Y and Z only 16.3%