PostgresSQL query in Grafana, create graph of Null and non-null elements

Viewed 41

I have a table with a NIF field, that field can be null or non-null. I wanted to create a graph where I could show the number of null and non-null elements.

The current consultation is:

SELECT
      0 as time,
      (
        case
            when nif = '' then 'Sin identificar'
            when nif != '' then 'Identificados'
            else nif
        end
      ),
      count(nif)
    FROM conversations
    WHERE $__timeFilter("fecha")
    GROUP BY time, nif
    ORDER BY 3 desc

But in the case of non-null only in account 1 element, when there are more

enter image description here

1 Answers

In the end I did not solve with this query:

SELECT
  0 as time,
  SUM(CASE WHEN nif = '' then 1 else 0 END) as noIdentificados,
  SUM(CASE WHEN nif != '' then 1 else 0 END) as Identificados
FROM conversations
WHERE $__timeFilter("fecha")  and etiqueta = '${etiqueta:raw}' 
GROUP BY 1
Related