Jump to content

summation of results


marmato

Recommended Posts

Hi guys,

I have a database called "Online Cars" containing a table called "status" which have 3 columns :source(text) ,destination (text) and status (int)
I wanna select a specific source and destination to get all the status entries for them and then get the mean and variance of these statuses
anyone can help me ?

 

my code :

 

<?php
$con = mysql_connect("localhost","root","");

$db = mysql_select_db("online cars");
$query = mysql_query("SELECT `Status` FROM `status` WHERE source = 'cairo' and destination = 'alex'");
while($row = mysql_fetch_assoc($query))
{
echo $row['Status']."<br>";

}
?>
.........................
the result is
1
2
5
4
3
4
i want to know how to get the summation and variance of these results

 

 

Link to comment
https://forums.phpfreaks.com/topic/276813-summation-of-results/
Share on other sites

try

SELECT s.source, s.destination, av.mean,
    AVG((s.status - av.mean)*(s.status - av.mean)) as variance
FROM status s
    INNER JOIN
        (
        SELECT source, destination, AVG(status) as mean
        FROM status
        GROUP BY source, destination
        ) as av
        USING (source, destination)
GROUP BY source, destination;

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.