使用SQL Select语句更新临时表的问题

时间:2014-07-11 19:15:18

标签: php mysql sql

您能否请一看这段代码,让我知道为什么我无法更新$query3上的临时表

$query = "CREATE TEMPORARY TABLE IF NOT EXISTS `charts_ecolo_yes` (


           SET `econo_sum_projects` = (SELECT COUNT(`project`) FROM `ecolo-cu-yes`  WHERE c_1000=1 ),
       SET `econo_sum_powerline` = (SELECT SUM(`powerline_length`) FROM `ecolo-cu-yes`  WHERE c_1000=1 ),
       SET `econo_sum_roads` = (SELECT SUM(`road_length`) FROM `ecolo-cu-yes`  WHERE c_1000=1 ),
       SET `econo_sum_cost` = (SELECT SUM(`cost_per_year`) FROM `ecolo-cu-yes`  WHERE c_1000=1 ),
       SET `econo_sum_penstlock` = (SELECT SUM(`penstlock` FROM `ecolo-cu-yes`  WHERE c_1000=1 )
        ";
$con->query($query3);
$query4 = "SELECT *  FROM `charts_ecolo_yes`" ;
$results = $con->query($query4);
if ($results) {
    $row = $results->fetch_array(MYSQLI_NUM);
    $row = array_map('floatval', $row); // Convert strings to numbers
    echo json_encode($row);
}

Here是示例结果页面,即使在运行$con->query($query3);之后您仍可以看到,我仍然在最后的第5列获得默认值(100)。

由于

1 个答案:

答案 0 :(得分:1)

您的UPDATE查询语法错误,您不需要SET所有列。它应该是

$query3= " UPDATE `charts_ecolo_yes`
SET `econo_sum_projects` = some_value,
`econo_sum_powerline` = some_other_value,