<?php
$query1 = "CREATE VIEW current_rankings AS SELECT * FROM main_table WHERE date = X";
$query2 = "CREATE VIEW previous_rankings AS SELECT rank FROM main_table WHERE date = date_sub('X', INTERVAL 1 MONTH)";
$query3 = "CREATE VIEW final_output AS SELECT current_rankings.player, current_rankings.rank as current_rank LEFT JOIN previous_rankings.rank as prev_rank
ON (current_rankings.player = previous_rankings.player)";
$query4 = "SELECT *, @rank_change = prev_rank - current_rank as rank_change from final_output";
$result = mysql_query($query4) or die(mysql_error());
while($row = mysql_fetch_array($result)) {
echo $row['player']. $row['current_rank']. $row['prev_rank']. $row['rank_change'];
}
?>
所有查询都独立工作,但我真的很难将所有部分放在一个结果中,所以我可以将它与 mysql_fetch_array 一起使用。
我尝试创建视图和临时表,但每次它要么说表不存在,要么返回一个空的 fetch 数组循环......逻辑在那里但语法混乱我认为这是我第一次不得不这样做处理我需要合并在一起的多个查询。期待一些支持。非常感谢。