How to compute the sum over other sums in Snowflake
Solution 1:
SELECT
SUM(Q1) AS sumQ1
, SUM(Q2) AS sumQ2
, SUM(Q3) AS sumQ3
, SUM(Q4) AS sumQ4
, SumQ1 + SumQ2 + SumQ3 + SumQ4 AS Total
FROM DT
I haven't tested it, but I think that should do the trick.
Edit: To address the point made Simeon's answer. We create the example data in the OP:
CREATE OR REPLACE TABLE DT (ID number, Q1 number, Q2 number, Q3 number, Q4 number);
INSERT INTO DT VALUES
(1,1,2,3,4),
(2,0,1,2,3),
(3,3,2,1,0);
Then, my answer above provides the following output:
SUMQ1 SUMQ2 SUMQ3 SUMQ4 TOTAL
4 5 6 7 22
which is the output desired by the OP.