我與後續數據表的數據庫:PHP和MySQL領域的PHP和回聲
sales
expenses
taxes
earnings
當我賣一些產品將其添加到銷售一個項目,同樣要費用,同時我加費,稅銷售和收入時也會自動添加。它們位於相同的數據庫但不同的表中。
我需要將這些字段彙總在一起。我這樣做,無需逐一的問題是這樣的:
<?php
$query = mysqli_query($db, "SELECT SUM(total) AS `total` FROM `sales`");
while($result = mysqli_fetch_assoc($query)){
echo number_format($result['total'],0,',','.');}
?>
和
<?php
$query2 = mysqli_query($db, "SELECT SUM(expense) AS `expense` FROM `expenses`");
while($result2 = mysqli_fetch_assoc($query2)){
echo number_format($result2['expense'],0,',','.');}
?>
如何總結這兩個和回聲結果例子:
sales - expense = value ?
很好,非常感謝 –