如何统一日期并添加各自的时间?

How to unite dates and add their respective times?

如何对日期进行分组并添加各自的时间?

我有以下数据和查询:

编辑:

查询:

select distinct(date_format(initial_date, '%Y-%m-%d')) as date, date_format(initial_date, '%hh%i') as time from periods
group by initial_date
order by initial_date

意识到有重复的红色日期,我正在尝试对这些日期进行分组,并对那些绿色的日期求和。即只形成一个日期值,不重复。

有人可以帮忙吗?

您可以对 date 和 sum() 使用 group by

  select date_format(initial_date, '%Y-%m-%d') as date, sum(hour(initial_date)) time
  from periods 
  group  by  date_forma(initial_date, '%-%m-%d') 
  order by initial_date

或者如果您希望始终在同一行上使用 group_concat

  select date_format(initial_date, '%Y-%m-%d') as date, group_concat(date_format(initial_date, '%hh-%i')) time
  from periods 
  group  by  date_forma(initial_date, '%-%m-%d') 
  order by initial_date