所以我在我的项目中计算数据的方差,我发现postgresql中有一个方法var_samp()可以自动计算它,但它似乎不能在我的代码中工作。它给我一个错误说:
严重性:警告
消息:pg_query():查询失败:错误:语法错误在或附近"' variance'"第4行:VAR_SAMP(total_score)AS'方差',^
文件名:postgre / postgre_driver.php
行号:242
这是我数据库中的表: results table in databse
这是我模型的代码:
public function computeVariance($exam_no){
$query = $this->db->query("SELECT COUNT(total_score) AS N,
SUM(total_score) AS sum,
AVG(total_score) AS mean,
VAR_SAMP(total_score) AS 'variance',
MIN(total_score) AS minimum,
MAX(total_score) AS maximum
FROM results
WHERE exam_no = '$exam_no';");
return $query->result();
}
有人能告诉我为什么方法var_samp()不起作用?