marmato Posted April 11, 2013 Share Posted April 11, 2013 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 is125434i want to know how to get the summation and variance of these results Quote Link to comment https://forums.phpfreaks.com/topic/276813-summation-of-results/ Share on other sites More sharing options...
Barand Posted April 11, 2013 Share Posted April 11, 2013 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; Quote Link to comment https://forums.phpfreaks.com/topic/276813-summation-of-results/#findComment-1424215 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.