Table with values grouped by day

Version of grafana is 6.7.2
I want to create a table with daily information about production, some information is the max value of a day, other the average, other the last no zero value of a day.
What i have made is this:

SELECT
  $__timeGroupAlias(data_hora,$__interval),
  max(ocioso_m) as "Alimentador ocioso",
  max(descargas) as "Descargas"
FROM operacao_al
WHERE
  $__timeFilter(data_hora) AND
  al_id = 1
GROUP BY date(data_hora)
ORDER BY $__timeGroup(time,$__interval)

To take the max value of it, but i want to take the last non zero value of a day:

SELECT
  $__timeGroupAlias(data_hora,$__interval),
  media_carga_ton
FROM operacao_al
WHERE (al_id = 1) and (media_carga_ton > 0) and data_hora in (
  select max(data_hora) from operacao_al where al_id = 1 and media_carga_ton > 0 and $__timeFilter(data_hora) group by date(data_hora)
) and $__timeFilter(data_hora)
GROUP BY date(data_hora)
ORDER BY $__timeGroup(time,$__interval)

So i want to select 7 or 30 days and have the date - and the value of every day on a line.
But what is happening is this:

Well i expected date - information on the same line.

So i will apreciate help.

I changed this, and solved the problem:

SELECT
 date(data_hora) as time,
  max(ocioso_m) as "Alimentador ocioso",
  max(descargas) as "Descargas"
FROM operacao_al
WHERE
  $__timeFilter(data_hora) AND
  al_id = 1
GROUP BY date(data_hora)
ORDER BY $__timeGroup(time,$__interval)
SELECT
  date(data_hora) as time,
  media_carga_ton
FROM operacao_al
WHERE (al_id = 1) and (media_carga_ton > 0) and data_hora in (
  select max(data_hora) from operacao_al where al_id = 1 and media_carga_ton > 0 and $__timeFilter(data_hora) group by date(data_hora)
) and $__timeFilter(data_hora)
GROUP BY date(data_hora)
ORDER BY $__timeGroup(time,$__interval)

Thats a problem, now i select the day 15 for example, and have the information of that day, but with date on table 14. How do fix this?


This topic was automatically closed after 365 days. New replies are no longer allowed.