如何多次汇总mysql?

时间:2017-10-25 04:11:56

标签: php mysql

我有一个脚本,可以在te字段中总结所有内容" total"还可以。

$cleaner = $connection->query("SELECT *,SUM(total) as total FROM ventas where fecha='$datenow'");

但 我想创建更多过滤器,当caja是钉子

$cleanerx = $connection->query("SELECT *,SUM(total) as total FROM ventas where fecha='$datenow' and caja='NAILS'");

为什么不工作,我在php阅读教程,但我不明白为什么不工作。

1 个答案:

答案 0 :(得分:1)

你可以这样做:

$cleaner = $connection->query("SELECT *,SUM(total) as total,(SELECT SUM(total) as total FROM ventas where fecha='$datenow' and caja='NAILS') as totalnails FROM ventas where fecha='$datenow'");