我正在尝试计算今天的销售总额,但这不起作用。 它有效,如果我删除日期部分...
# This works and will gives out the total:
$result = mysql_query("SELECT SUM(grand_total) AS value_sum FROM order");
$row = mysql_fetch_assoc($result);
$sum = $row['value_sum'];
# This doesn't work:
$result = mysql_query("SELECT SUM(grand_total) AS value_sum FROM new_order WHERE date = CURDATE()");
$query = mysql_query($result) or die ('Error: ' . mysql_error());
$row = mysql_fetch_assoc($result);
$sum = $row['value_sum'];
此外,如何在此之后获得此专栏的每月总数?
答案 0 :(得分:0)
如果date
字段为DATETIME
类型,则尝试此sql语句:
SELECT SUM(`grand_total`) AS value_sum
FROM `order`
WHERE DATE(`date`) = CURDATE()