0

我想从我的表中选择过去 7 天上传的数据。这是我到目前为止所拥有的,但它不起作用。

$sql9="SELECT SUM(TruckDamage) 
WHERE DATEDIFF(`upload_date`, CURRENT_DATE) < 7 
AS     TotalTruckDamageSum FROM jwtdriversbank2";  
$result9=mysql_query($sql9);
$rows9=mysql_fetch_assoc($result9);
$sum8=$rows9['TotalTruckDamageSum'];
?>
<div>
Total Truck Repair Cost's: &pound;<?echo $sum8?><br>

有人可以帮忙吗?

4

3 回答 3

0

问题是您的查询无效。您将 TotalTruckDamageSum 分配给WHERE. 第二个语法错误FROM应该是 before WHERE。最后但并非最不重要的是,如果您想获得DATEDIFF.

应该:

$sql9="SELECT SUM(TruckDamage) AS TotalTruckDamageSum FROM `jwtdriversbank2` WHERE DATEDIFF(CURRENT_DATE,`upload_date`) <= 7";
于 2013-08-12T09:06:39.313 回答
0
$sql9="SELECT SUM(TruckDamage) AS     TotalTruckDamageSum 
                  where upload_date >= DATE_SUB(now(), INTERVAL 7 DAY)
                  FROM jwtdriversbank2";  

$result9=mysql_query($sql9);
$rows9=mysql_fetch_assoc($result9);
$sum8=$rows9['TotalTruckDamageSum'];
?>
<div>
Total Truck Repair Cost's: &pound;<?echo $sum8?><br>
于 2013-08-12T09:07:29.380 回答
0

应该

sql9="SELECT SUM(TruckDamage) 

AS     TotalTruckDamageSum FROM jwtdriversbank2 WHERE DATEDIFF(`upload_date`, CURRENT_DATE()) < 7";  
于 2013-08-12T09:05:13.207 回答