Q:

Total up columns using sub queries in the SELECT list

I am creating a table that holds total count of rows in three other tables and then work out the totals of all combined. 
So far I have :

SELECT (SELECT COUNT(*) FROM T1) T1,
       (SELECT COUNT(*) FROM T2) T2,
       (SELECT COUNT(*) FROM T3) T3,
       (SELECT (T1+T2+T3)) TOTAL

However I get an error message that says T1, T2 and T3 are invalid column names. If I remove the TOTAL subquery then it executes fine.
Any ideas please?

A:

You can use cte :
WITH t AS (
     SELECT (SELECT COUNT(*) FROM T1) T1,
            (SELECT COUNT(*) FROM T2) T2,
            (SELECT COUNT(*) FROM T3) T3
)

SELECT T1, T2, T3, (T1 + T2 + T3) AS TOTAL
FROM t;  

