开发者

24 hours = 24 values [duplicate]

This question already has answers here: Closed 12 years ago.

Possible Duplicate:

24 hours of values

Hello,

how do write the sql to get a value from each hour in one selected day ???

Meaning 24 values: 12,34,22,32,45,23,23 etc.

My table has 3 columns: | date (Y-m-d) | time (00:00:00) | power (int) |

I can only get 1 value at a time, and that is NOT what I want...

    <?php
$choice = (isset($_POST['choice'])) ? date("Y-m-d",strtotime($_POST['choice'])) : date("Y-m-d"); 
$con = mysql_connect("localhost","root","xxxxxxxxxx");  
if (!$con)  {  
die('Could not connect: ' . mysql_error());  
}  
mysql_select_db("inverters", $con);  
$sql = "SELECT date, power AS choice 
FROM feed 
WHERE date = '".$choice."' 
ORDER BY HOUR(time)"; 
$res =开发者_如何学Python mysql_query($sql) or die('sql='.$sql."\n".mysql_error()); 
$row = mysql_fetch_assoc($res); 
echo $row['choice'].'<br />'; 
?>


If you use GROUP BY Hour(time) you can do aggregate calculations on that date by the hour.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜