Exercise #59

Calculate the cash balance of each buy-back center for the database with money transactions being recorded not more than once a day. Result set: point, balance.

Solution 2.2.1

SELECT ss.point, ss.inc - dd.out
FROM (SELECT i.point, SUM(inc) AS inc
      FROM Income_o i
      GROUP BY i.point
     ) AS ss,
     (SELECT o.point, SUM(out) AS out
      FROM Outcome_o o
      GROUP BY o.point
     ) AS dd
WHERE ss.point = dd.point;
🚫
[[ error ]]
[[ column ]]
NULL [[ value ]]

The subqueries in the FROM clause calculate, for each point, the sum of cash receipts and payouts respectively. These subqueries are combined based on matching point numbers, which allows calculating the cash balance for each point on a line-by-line basis using the formula ss.inc-dd.out.

At first glance, everything seems to be correct, but solution 2.2.1 has a mistake. Try to find it.

T&S

To solve the problem on SQL-EX.RU