如何编写一个脚本来计算两个值之间的百分比变化,然后将结果提交到一个新的MYSQL表?
您可以在一个简单的SQL查询中完成它,而不需要在PHP中做任何事情:
假设要插入的表称为newTable
,并有两列(ID
是自动增量,percy
是col1/col2
与表2的百分比值):
insert into newTable
(ID, percy)
select
null,
col1/col2
from
table2
where
somecondition=someOtherCondition
或者,如果您想获得原始行的ID(称为myID),并将计算出的百分比插入到新表中:
insert into newTable
(ID, percy)
select
myID,
col1/col2
from
table2
where
somecondition=someOtherCondition