Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何从表列中查找百分比值_Php_Mysql_Percentage - Fatal编程技术网

Php 如何从表列中查找百分比值

Php 如何从表列中查找百分比值,php,mysql,percentage,Php,Mysql,Percentage,我正在尝试查找表中具有相同id的每个数值的百分比值。例如,如果我的表格由以下内容组成: id answer points 1 answer 1 3 1 answer 2 1 1 answer 3 10 1 answer 4 5 1 answer 5 6 1 answer 6 10 1 answer 7 10 1 answer 8 2

我正在尝试查找表中具有相同id的每个数值的百分比值。例如,如果我的表格由以下内容组成:

id  answer          points
1   answer 1        3
1   answer 2        1
1   answer 3        10
1   answer 4        5
1   answer 5        6
1   answer 6        10
1   answer 7        10
1   answer 8        2

如果最大点数为80,如何以百分比形式显示数据库中的当前结果(点数)?

如果我理解正确:

select   100 * (points / 80) as Percentage
from     YourTable
您甚至可以考虑计算总点数:

select   100 * (points / (select sum(points) from YourTable)) as Percentage
from     YourTable
这样,您只需将答案添加到表中,计算将相应调整。

求和()点并将其除以80:

select id, sum(points), sum(points)/80 as percentage
from table
group by id

为此,您可以使用
分组方式
,如

select maxpoint * 0.1 as maxpoint_percent
from (
select id, sum(points) as maxpoint
from table1
group by id ) xx
where maxpoint >= 80;

如何使用PHP在网页中显示这些内容?执行查询,循环搜索结果并以您希望的格式显示它们。像这样?如何使用PHP在网页中显示?如何使用PHP在网页中显示?