Complex SQL
Question

Hello SQL expert in outsystems

I have a problem and let me ask some questions.

My problem is I have two table(Old table and New table)

I select data by person for 12 months from Old table and calculate total_1 and total_2.

The result is inserted in New table.

please check out my picture.

How can I achieve this two total in SQL.

Is is possible to solve using SQL?

If any other way please point out me.

Thanks.


SQLTotal.png

mvp_badge
MVP

Hi May Zin Linn,

You can do this with an SQL instead of an aggregate, like:

SELECT {entity}.[col1], 
       {entity}.[num1], 
       {entity}.[num2], 
       {entity}.[num1] + {entity}.[num2] RowTotal
FROM {entity}
UNION
SELECT 'Total' AS Total, 
       SUM({entity}.[num1]) AS Num1Total, 
       SUM({entity}.[num2]) AS Num2Total, 
       SUM({entity}.[num1] + {entity}.[num2]) RowTotal
FROM {entity}

Regards,

Daniel


Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.