The NULL field does not return

2

Good day, I would like you to help me with this problem, this is my query:

SELECT Nombre, Cedula, sum(HorasTrabajo) as HorasTrabajo FROM reportebeteitiva
                                       group by Cedula WITH ROLLUP;

Result in:

_________________________________________
|  Nombre  |   Cedula   |  HorasTrabajo |
-----------------------------------------
|Gragorio  | 105460452  |       8       |
-----------------------------------------
|Valentina | 10546565   |      16       |
-----------------------------------------
| Keylor   | 105632514  |      26       |
-----------------------------------------
| Keylor   |     NULL   |      50       |
-----------------------------------------

As you can see, the WITH ROLLUP works properly for me, but in the final row in the result row it does not return the NULL in Keylor, that's what still does not work for me, thanks for the help.

    
asked by CristianLRS1997 28.05.2018 в 17:31
source

1 answer

2

After so much searching I found an answer that fits the result I expected:

SELECT * FROM 
(
  SELECT Nombre, Cedula, sum(HorasTrabajo) as HorasTrabajo FROM reportebeteitiva 
     group by Nombre, Cedula WITH rollup
)A WHERE isnull(Nombre) = isnull(Cedula);

This is the result:

_________________________________________
|  Nombre  |   Cedula   |  HorasTrabajo |
-----------------------------------------
|Gragorio  | 105460452  |       8       |
-----------------------------------------
|Valentina | 10546565   |      16       |
-----------------------------------------
| Keylor   | 105632514  |      26       |
-----------------------------------------
|   NULL   |    NULL    |      50       |
-----------------------------------------
    
answered by 28.05.2018 в 18:23