Du kan nemt gøre dette med en UNION ALL
. Nøglen er, at den master_code
felt skal være den samme datatype som strengen total
så du bliver nødt til at konvertere det:
select cast(master_code as varchar(10)) master_code, jan
from yourtable
union all
select 'Total', sum(jan)
from yourtable
Eller du kan bruge GROUP BY with ROLLUP
:
select
case
when master_code is not null
then cast(master_code as varchar(10)) else 'total' end master_code,
sum(jan) Jan
from yourtable
group by master_code with rollup