# Data each minute, agrupate by each hour of the day

**URL:** <https://community.grafana.com/t/data-each-minute-agrupate-by-each-hour-of-the-day/37895>\
**Category:** General\
**Created:** [October 13, 2020, 3:01pm UTC](https://community.grafana.com/t/data-each-minute-agrupate-by-each-hour-of-the-day/37895 "2020-10-13T15:01:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![rodriguezjota](https://avatars.discourse-cdn.com/v4/letter/r/54ee81/32.png) [@rodriguezjota](https://community.grafana.com/u/rodriguezjota)\
**Post date:** [October 13, 2020, 3:01pm UTC](https://community.grafana.com/t/data-each-minute-agrupate-by-each-hour-of-the-day/37895/1 "2020-10-13T15:01:15Z")

</div>

Dear colleagues,

I have a Mysql Table where I am registering each minute the value of a counter…  
example : 14:01:00 (9080) 1  
4:02:00: (10020)  
4:03:00 (10250)…

I would like to have a graphic bar with the total of each hour, so , i suppose that I should get the first value of each hour and the last one … por example: 14:00:00 (9000) and 14:59:58 (13000) and substract 13000-9000 in order to have the total I have produced during that hour: 40000.

How can I do it for a bar with 24 bars? , I mean , one bar for each hour of the day…

Many thanks in advance!!

My actual trend:

 ![image](https://us1.discourse-cdn.com/grafana/original/2X/f/f4c717ece7db0f5aa0cc560e48ede0d4fffe4fab.png)

---

<div class="post-metadata">

**Author:** ![deejayluk](https://avatars.discourse-cdn.com/v4/letter/d/cc9497/32.png) [@deejayluk](https://community.grafana.com/u/deejayluk)\
**Post date:** [October 14, 2020, 6:29am UTC](https://community.grafana.com/t/data-each-minute-agrupate-by-each-hour-of-the-day/37895/2 "2020-10-14T06:29:46Z")

</div>

Hi

Check this:

> ```
> SELECT   
> DATEADD(HOUR, DATEDIFF(HOUR, 0, fechaini), 0) as time,
> namevar as metric,
> max(valuevar)-min(valuevar) as valuevar
> FROM FS_92_velocidades
> group by DATEADD(HOUR, DATEDIFF(HOUR, 0, fechaini), 0), namevar
> 
> ```

---

<div class="post-metadata">

**Author:** ![rodriguezjota](https://avatars.discourse-cdn.com/v4/letter/r/54ee81/32.png) [@rodriguezjota](https://community.grafana.com/u/rodriguezjota)\
**Post date:** [October 14, 2020, 8:22am UTC](https://community.grafana.com/t/data-each-minute-agrupate-by-each-hour-of-the-day/37895/3 "2020-10-14T08:22:40Z")

</div>

Many thanks @deejayluk,

Being honest, I see and I achieve understand what you are trying to do, but I dont know what I can change in order to see the data…

Let me paste the result:

 ![image](https://us1.discourse-cdn.com/grafana/original/2X/b/bd7afd6e1ba05f06db223c7cc278161e6f154fcb.png)

---

<div class="post-metadata">

**Author:** ![deejayluk](https://avatars.discourse-cdn.com/v4/letter/d/cc9497/32.png) [@deejayluk](https://community.grafana.com/u/deejayluk)\
**Post date:** [October 14, 2020, 10:04am UTC](https://community.grafana.com/t/data-each-minute-agrupate-by-each-hour-of-the-day/37895/4 "2020-10-14T10:04:26Z")

</div>

My code is for Microsoft SQL Server connection, but you have MySQL.  
I think dateadd is not recognized by MySQL.  
Check this:

> date\_format(fechaini, ‘%Y-%m-%d %H:00:00’)

or check DATE\_ADD

---

<div class="post-metadata">

**Author:** ![pooh](https://avatars.discourse-cdn.com/v4/letter/p/f05b48/32.png) [@pooh](https://community.grafana.com/u/pooh)\
**Post date:** [October 14, 2020, 11:13am UTC](https://community.grafana.com/t/data-each-minute-agrupate-by-each-hour-of-the-day/37895/5 "2020-10-14T11:13:58Z")

</div>

> **[MySQL :: MySQL 8.0 Reference Manual :: 12.7 Date and Time Functions](https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html)**

  
#function\_date-add

Antony.
