Sum the max value of every day in grafana

Hello!
I have a value (from mysql datasource) that stores the total daily production of a machine in tons. This value is written all day long in the database, starting small at the beginning of the day and growing during the day. At midnight the machine zeroes the value by starting a new daily production.
So I need grafana to present me a sum of the maximum values ​​obtained for each day, according to the selected period.
So I can calculate how many tons I have in 1 day or 1 week or even 1 year.
This is the table structure:

machine_id  |         data              | pruducao_ton
1                    2019-04-17 14:43        235
1                    2019-04-17 14:40        230
1                    2019-04-17 14:37        226
...

This is the query that i have now:

SELECT
  data AS "time",
  producao_ton AS "producao_ton"
FROM operacao_br
WHERE
  $__timeFilter(data)
ORDER BY data

But this only gives me the maximum value of the whole period, when i select the Value -> Stat -> “Max”

Here is the right query to make it:

SELECT
  distinct(date(data)) AS "time",
  max(producao_ton) AS "producao_ton"
FROM operacao_br
WHERE
  $__timeFilter(data)
group by date(data)

Problem solved.

1 Like