【发布时间】:2010-12-03 22:36:08
【问题描述】:
可能重复:
24 hours of values
你好,
如何编写 sql 以从选定日期的每个小时中获取一个值 ???
表示 24 个值:12、34、22、32、45、23、23 等
我的表有 3 列:|日期 (Y-m-d) |时间 (00:00:00) |功率(整数)|
我一次只能获得 1 个值,这不是我想要的...
<?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 = mysql_query($sql) or die('sql='.$sql."\n".mysql_error());
$row = mysql_fetch_assoc($res);
echo $row['choice'].'<br />';
?>
【问题讨论】:
-
请编辑原始问题而不是重复发布。