So I am computing the variance of my data in my project, I have found out that there is a method var_samp() in postgresql that automatically computes it but it doesn't seem to work in my code. It gives me an error that says:
Severity: Warning
Message: pg_query(): Query failed: ERROR: syntax error at or near "'variance'" LINE 4: VAR_SAMP(total_score) AS 'variance', ^
Filename: postgre/postgre_driver.php
Line Number: 242
here is the table in my database: results table in databse
and here is the code of my model:
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();
}
Can someone tell me why the method var_samp() not working?