Skip to content
Advertisement

Sumarize colums to get just one value

I get the result shown below, but I need to get only one row with the sum of the column QTD_PARC and VL_TIT, this in the SQl Server, can someone help me please?

enter image description here

Advertisement

Answer

You can use sum() with group by clause. If you want to calculate mandt, nf_id, exercicio, num_tit, empresa, filial, ind_emit, desc_tit, ind_tit wise sum of qtd_parc and vl_tit then you can select mandt, nf_id, exercicio, num_tit, empresa, filial, ind_emit, desc_tit and ind_tit along with sum(qtd_parc) and sum(vl_tit) and you need to mention mandt, nf_id, exercicio, num_tit, empresa, filial, ind_emit, desc _tit (i.e., all the columns not included in an aggregate function like sum) in your group by clause:

 Select mandt,nf_id,exercicio,num_tit,empresa,filial,ind_emit,desc_tit, 
 ind_tit,sum(qtd_parc)qtd_parc,sum(vl_tit)vl_tit
 from MyTable
 group by mandt,nf_id,exercicio,num_tit,empresa,filial,
 ind_emit, desc_tit, ind_tit
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement