Multiply 2 Columns and Add to the MYSQL End

0

I would like you to help me, I have 2 tables, and my intention is as follows, I write it in the image:

This is the query that I have:

$query = "SELECT Nombre, Cedula, sum(HorasTrabajo) as HorasTrabajo, sum(VC) as VC, ValorVC, sum(VR) as VR, ValorVR, sum(PA) as PA, ValorPA, sum(PRG) as PRG, ValorPRG, 
                   sum(PRI) as PRI, ValorPRI, sum(TAC) as TAC, ValorTAC, sum(TRM) as TRM, ValorTRM, sum(MLC) as MLC, ValorMLC, sum(BENDA) as BENDA, ValorBenda,
                   sum(EVS) as EVS, ValorEVS, sum(ADM) as ADM, ValorADM, sum(CRG) as CRG, ValorCRG, sum(CDS) as CDS, ValorCDS, sum(CNST) as CNST, ValorCNST,
                   sum(MTA) as MTA, ValorMTA, sum(MTDCH) as MTDCH, ValorMTDCH, sum(MTDPT) as MTDPT, ValorMTDPT, sum(Otros) as Otros, ValorOtros, FROM reportebeteitiva
                    SUM(VC*ValorVC) AS JIJIJI GROUP BY  Cedula 

What I want is for the VC column to be multiplied by the VC Value, but each individual record and the total of these multiplications add up and give me the result in the total field. Grcias for the help.

    
asked by CristianLRS1997 31.05.2018 в 00:12
source

1 answer

0

To make the query look like the image, you can use union in the following way:

SELECT Nombre, Cedula, sum(HorasTrabajo) as Horas, sum(VC) as VC, ValorVC
FROM reportebeteitiva
GROUP BY Cedula
UNION
SELECT '', '', 'Total','', SUM(VC*ValorVC)
FROM reportebeteitiva

I hope you find it helpful, greetings.

    
answered by 31.05.2018 в 00:38