I have wrote SQL query pulling 6 columns from 4 different tables, however I need on the last row total just for one column. It should look like this.
Advertisement
Answer
Well, you can do:
with cte as ( <your query here> ) select cte.* from cte union all select 'Total', 'n/a', 'n/a', 'n/a', 'n/a', 'n/a', sum(consentv), 'n/a' from cte;
Notes:
- This does not guarantee that
Total'
is at the end. You might needorder by
. - This assumes that all other columns have strings.