Add in total MYSQL

1

I have these two tables:

                REPORTEBETEITIVA
_______________________________________________________
|  idReporteBeteitiva   |    HorasTrabajo |Trabajador |  
-------------------------------------------------------
|        1              |         8       |     1     |
-------------------------------------------------------
|        2              |         8       |     1     |
-------------------------------------------------------
|        3              |        14       |     2     |
-------------------------------------------------------


                        TRABAJADOR
    ________________________________________
    |  idTrabajador   |  Nombre  |  Cedula |  
    ----------------------------------------
    |        1        |   PEDRO  | 1054632 |
    ----------------------------------------
    |        2        |   CAMILO | 1234555 |
    ----------------------------------------

I want to add the total hours worked, but I already have this query that groups me the hours by the "Cedula":

SELECT trabajador.Nombre, sum(HorasTrabajo) as HorasT FROM 
reportebeteitiva INNER JOIN trabajador ON reportebeteitiva.Trabajador = 
trabajador.idTrabajador group by trabajador.Cedula;

then I only need the part of TOTAL = 28.

That's how it would look:

       ______________________
       |  Nombre |  HorasT  |   
       ----------------------
       |   Pedro |   16     |
       ----------------------
       |  Camilo |   12     | 
-----------------------------
|TOTAL           |   28     |
-----------------------------

Thanks for the help: D

    
asked by CristianLRS1997 25.05.2018 в 23:35
source

1 answer

1

You just have to add the WITH ROLLUP clause like this:

SELECT trabajador.Nombre, sum(HorasTrabajo) as HorasT FROM 
reportebeteitiva INNER JOIN trabajador ON reportebeteitiva.Trabajador = 
trabajador.idTrabajador 
group by trabajador.Cedula WITH ROLLUP;
    
answered by 25.05.2018 / 23:42
source