それを正しく理解していれば、解決策はそれほど複雑である必要はありません。年と値を取得するための単純な SELECT クエリ。PHP でループを使用してパーセンテージを計算できます。このようなもの:
<?php
// Get all the data from the database.
$sql = "SELECT year, value FROM exports";
$stmt = $pdo->query($sql);
// An array to store the precentages.
$percentages = [];
// A variable to keep the value for the last year, to be
// used to calculate the percentage for the current year.
$lastValue = null;
foreach ($stmt as $row) {
// If there is no last value, the current year is the first one.
if ($lastValue == null) {
// The first year would always be 100%
$percentages[$row["year"]] = 1.0;
}
else {
// Store the percentage for the current year, based on the last year.
$percentages[$row["year"]] = (float)$row["value"] / $lastValue;
}
// Overwrite the last year value with the current year value
// to prepare for the next year.
$lastValue = (float)$row["value"];
}
結果の配列は次のようになります。
array (
[1992] = 1.0,
[1993] = 1.2,
[1994] = 0.95
... etc ...
)