Percentage calculation, and then arrange the problem. There is a table tab field a1a2 & nbsp; PHPcodea1a2 Wang 0 Wang 1 Wang 3 Li 1 li 2 calculation a2 Li Wang & gt; 0 value has two Wang's total percentage calculation, then arrange the problem.
Table tab field a1 a2
PHP code
A1 a2 Wang 0 Wang 1 Wang 3 Li 1 li 2
In a2, the value of king> 0 has two values of King. a total of three values are 2/3, and the output is 66%.
Li is 100% and then arranged in ascending order by percentage
Output result display
PHP code
Li 100% Wang 66%
------ Solution --------------------
Select a1, sum (if (a2> 0, 0)/count (*) * 100 as num from tab group by a1 order by num desc
Formula:
Sum (if (a2>, 0) counts the number of a2 values greater than 0.
Count (*) count the total number
Number of numbers greater than 0/total number * 100
Yes
Percentage of the population greater than 0, which is a basic arithmetic operation.