Forum Moderators: coopster
'id' 'cluster_name' 'insert_dt_tm' 'nodes_available'
'1' 'Atlantis' '2/1/2005 00:03:00' '45'
2 Atlantis 2/1/2005 01:03:00 45
3 Atlantis 2/1/2005 02:03:00 45
4 Atlantis 2/1/2005 03:03:00 45
5 Atlantis 2/1/2005 04:03:00 45
6 Atlantis 2/1/2005 05:03:00 45
I am trying to create an average for nodes available for the day and have the output to resemble
Atlantis 2/1/2005 60
Atlantis 2/2/2005 60
I have the basics down for PHP but need some guidance on this one.
Any help is greatly appreciated.
Pete
[edited by: ergophobe at 9:34 pm (utc) on April 8, 2005]
[edit reason] Data reformatted and snipped [/edit]
Let me begin by thanking you both for replying. I truly appreciate the assitance.
This is a MySQL database that is being fed the data by several computer clusters. The data begins as text files that is being parsed and inserted into the database.
I will give a go with your recommendation deizu and hopefully get the results I am trying to achieve.
I believe there is a way to capture the timestamp in various formats. Should it be changed to make querying against it easier?
Pete
I was testing the query through phpMyAdmin and was given the error.
Once I implemented the query through a PHP page, the desired results was achieved.
<?php
// Make a MySQL Connection
mysql_connect("", "", "") or die(mysql_error());
mysql_select_db("") or die(mysql_error());
// Retrieve all the data
$result = mysql_query("SELECT cluster_name,
DATE_FORMAT(insert_dt_tm, '%Y-%m-%d') as day,
AVG(nodes_available) as nodes_average
FROM Nodes_Available_February_2005
GROUP BY cluster_name, day")
or die(mysql_error());
echo "<table border='1'>";
echo "<tr> <th>Name</th> <th>Day</th> <th>Average</th> </tr>";
// store the record of the "example" table into $row
while($row = mysql_fetch_array( $result )) {
// Print out the contents of the entry
echo "</td><td>";
echo "".$row['cluster_name'];
echo "</td><td>";
echo "".$row['day'];
echo "</td><td>";
echo "".$row['nodes_average'];
echo "</td></tr>";
}
echo "</table>";
?>
Thanks to all who aided, especially deizu for constructing the query for me. I am certain I will need some more assistance in the very near future.
Pete