MySQL 当我有 UTC 时按日期分组

MySQL Group By Date when I have UTC

我在 MySQL 数据库中有数据,其中包含一个值和输入该值的 UTC 时间,如下所示:

----value---|-----------utc---------
     8      |    2021-05-28 16:59:24
------------------------------------
    12      |    2021-05-28 20:51:11
------------------------------------
     3      |    2020-12-12 13:45:34
------------------------------------

有了这个,我怎么能按它们的 UTC 日期 而不是时间对这些值进行分组,像伪查询 SELECT value, utc GROUP BY utc 这样的东西 return按日期分组的所有值的总和,如:

----value---|-----------date---------
     20     |      2021-05-28
------------------------------------
      3     |      2020-12-12
------------------------------------

任何帮助将不胜感激,谢谢!

只需使用date()函数:

select date(utc), sum(value)
from t
group by date(utc);

或特定日期:

select sum(value)
from t
where utc >= '2021-05-08' and
      utc < '2021-05-09'