Skip to content
Advertisement

I have joined few tables and need total of the last column on the end of my query [closed]

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. enter image description here

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 need order by.
  • This assumes that all other columns have strings.
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement