'NULL AS OUT in SELECT statements

I am trying to solve this exercise:

Under the assumption that receipts of money (inc) and payouts (out) can be registered any number of times a day for each collection point [i.e. the code column is the primary key], display a table with one corresponding row for each operating date of each collection point. Result set: point, date, total payout per day (out), total money intake per day (inc). Missing values are considered to be NULL.

After several hours of headbanging I found this solution online:

SELECT X.POINT,X.DATE,SUM(OUT),SUM(INC) FROM (
    SELECT I.POINT,I.DATE,NULL AS OUT, SUM(I.INC) AS INC FROM INCOME I
    GROUP BY I.POINT,I.DATE
    UNION 
    SELECT O.POINT,O.DATE,SUM(O.OUT) AS OUT , NULL AS INC FROM OUTCOME O
    GROUP BY O.POINT,O.DATE) AS X
GROUP BY POINT,DATE

I tried to understand how this works. I googled all variations of "NULL AS OUT" but I could not find any explanation/concept. All results point out to stored procedures which is not what I am looking fro I think.

Can someone explain to me how these lines with "AS OUT" work, please?

SELECT I.POINT,I.DATE,NULL AS OUT, SUM(I.INC) AS INC FROM INCOME I
GROUP BY I.POINT,I.DATE
UNION 
SELECT O.POINT,O.DATE,SUM(O.OUT) AS OUT , NULL AS INC FROM OUTCOME O

On the left - The complete version of both tables On the right the result



Solution 1:[1]

out is probably an unfortunate name there, but other than that, there's nothing magical there.
"null" is the literal value of null.
"as out" assigns a column alias to the selected null.

Syntactically, this is the equivalent to any other literal value with any other alias, e.g., SELECT 'some_varchar_literal' AS some_alias or SELECT 123 AS numeric_alias.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mureinik