0
$r1 = mysql_query("
SELECT *, SUM(bps.price) as sum FROM accounts 
FULL JOIN bps on bps.id = mid
");
echo "Total price: ".$row['price']."<br>" ;
    while($row = mysql_fetch_array($r1))
      {
      echo $row['name']." <b>:::</b>  ".$row['mid']." <b>:::</b>  ".$row['price'];
      echo "<br />";
      }

这是我的查询。我需要得到列的总数(总和):bps.price 一些行有:10.5,其他 -5.5 等等......换句话说,有些是负值,有些是正值。它将列出所有结果然后在最后显示列价格的总和。

4

2 回答 2

1
select sum(bps.price) FROM accounts a
FULL JOIN bps on bps.id = a.mid

那会奏效的,对吧?它将对正负值求和,没关系。

于 2012-10-31T19:12:49.643 回答
1

这是否按您想要的方式工作?我不确定哪些列属于哪些表,只需根据需要编辑表名(a / b)...

$r1 = mysql_query("
SELECT *, sum(a.price) as sum FROM accounts as a 
FULL JOIN bps as b on a.mid = b.id
");
echo "Total price: ".$row['sum']."<br>" ;
    while($row = mysql_fetch_array($r1))
      {
      echo $row['a.name']." <b>:::</b>  ".$row['a.mid']." <b>:::</b>  ".$row['a.price'];
      echo "<br />";
      }
于 2012-10-31T19:14:27.630 回答