i have the following table:
date | value | Average |
---|---|---|
2021-04-07 18:00:00 | 5 | |
2021-04-07 18:00:00 | 10 | |
2021-04-07 18:02:00 | 5 | |
2021-04-07 18:02:00 | 4 | |
2021-04-07 18:03:00 | 5 | |
2021-04-07 18:03:00 | 8 |
And i want to know how could i calculate the average of values with the same timestamp, like this:
date | value | Average |
---|---|---|
2021-04-07 18:00:00 | 5 | 7,5 |
2021-04-07 18:00:00 | 10 | 7,5 |
2021-04-07 18:02:00 | 5 | 4,5 |
2021-04-07 18:02:00 | 4 | 4,5 |
2021-04-07 18:03:00 | 5 | 6,5 |
2021-04-07 18:03:00 | 8 | 6,5 |
I'm also wondering if it would be easier to calculate the average on a separate table so they won't repeat because there is more than one row with the same timestamp. Hope someone can help me with this, thanks in advance.
A simple query:
SELECT date, AVG(value) as avg_value FROM MyTable GROUP BY date