problems showing the null of a tables

0

Dear,

    CREATE TABLE 'preguntas' (
      'id_pregunta' int(11) NOT NULL,
      'nombre' varchar(200) COLLATE utf8_spanish_ci NOT NULL,
      'id_dimension_p' int(11) NOT NULL
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_spanish_ci;

   CREATE TABLE 'respuesta' (
  'id_respuesta' int(11) NOT NULL,
  'tipo_respuesta' set('1','2','3','4','5') COLLATE utf8_spanish_ci NOT NULL,
  'id_pregunta_r' int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_spanish_ci;

I have this query

SELECT preguntas.id_pregunta,respuesta.tipo_respuesta,
sum(IF (respuesta.tipo_respuesta is null ,0,1))  AS total_com
FROM preguntas 
LEFT JOIN respuesta
ON preguntas.id_pregunta=respuesta.id_pregunta_r
GROUP BY preguntas.id_pregunta,respuesta.tipo_respuesta

and this throws me

What should be thrown

I have to show the nulls to be able to graph any help or guidance will be appreciated

    
asked by alejandro henriquez 03.10.2017 в 21:18
source

1 answer

0

If you want to know how many answers you have you should use count, the query would like this:

SELECT preguntas.id_pregunta,IFNULL (respuesta.tipo_respuesta,0) AS respuesta , COUNT (respuesta.tipo_respuesta ) AS total_com FROM preguntas LEFT JOIN respuesta ON preguntas.id_pregunta=respuesta.id_pregunta_r GROUP BY preguntas.id_pregunta,respuesta.tipo_respuesta
    
answered by 03.10.2017 в 23:44