简体   繁体   中英

Calculate deduction in SQL with PHP language?

What I want: "Total number of income - Total number of expenses = Left"

I am still unable to make the code to calculate the deduction, kindly help me solve the code below, many Thank you.

    <?php
       include("connect-db.php");
       $left= mysql_query("Select income.inNo,expenses.eNo 
                          From income Join expenses On income.uId = expenses.uId")
       while($row = mysql_fetch_array($left))
     {
       echo "Left: RM".$row['SUM(inNo)'] - $row['SUM(eNo)'];
     }
    ?>
Select SUM(income.inNo) AS inc, SUM(expenses.eNo) AS exp,
SUM(income.inNo) - SUM(expenses.eNo) AS Leftover  
FROM income 
JOIN expenses On income.uId = expenses.uId
SELECT income - expense AS LEFT
FROM (SELECT SUM(inNo) AS income
      FROM income) AS i
CROSS JOIN (SELECT SUM(eNo) AS expense
            FROM expense) AS e

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM