MySQL standard deviance and variance
For this tutorial ,I have created following table in my-database.
CREATE TABLE IF NOT EXISTS `vehicle` ( `ID` int(30) NOT NULL AUTO_INCREMENT, `Type` varchar(40) NOT NULL, `Number` int(40) NOT NULL, PRIMARY KEY (`ID`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=9; -- -- Dumping data for table `vehicle` -- INSERT INTO `vehicle` (`ID`, `Type`, `Number`) VALUES (1, 'Toyota', 8), (2, 'Mercedes ', 9), (3, 'Volkswagen ', 10), (4, 'Volvo', 12), (5, 'Audi', 6), (6, 'Ford', 7), (7, 'Mitsubishi', 8), (8, 'Nissan', 9); |
|
<?php echo "<center><table bgcolor=#0b2d04> <tr bgcolor=#327423> <th><font color=#ffffff>ID</font></th> <th><font color=#ffffff>Type</font></th> <th><font color=#ffffff>Number</font></th> </tr>"; $username="root"; $password=""; $database="my_database"; mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query ="(SELECT * FROM vehicle)"; $result = mysql_query($query); while ($row = mysql_fetch_assoc($result)){ echo "<tr bgcolor=#d7eecb> <td>" .$row['ID']."</td> <td>" .$row['Type']."</td> <td>" .$row['Number']."</td> </tr>"; } echo "</table></center>"; $query2="SELECT SUM(Number), COUNT(ID), STD(Number), VARIANCE(Number) FROM vehicle"; $result2 = mysql_query($query2); mysql_close(); while ($row = mysql_fetch_assoc($result2)){ echo "<center>Sum of numbers:-".$row['SUM(Number)']."</center></br>"; echo "<center>standard deviance is:-".$row['STD(Number)']."</center></br>"; echo "<center>Variance is:-".$row['VARIANCE(Number)']."</center></br>"; echo "<center>Count is:-".$row['COUNT(ID)']."</center></br>"; } ?> |
|
No comments:
Post a Comment