简体   繁体   中英

Difference between datetime on the same column mysql

I need to get the difference between the dates of the same day and then get total of the month.

描述

With this query i get all dates of the actual month (12)

SELECT `fecha` FROM listado1 WHERE MONTH(`fecha`) = 12 and id_persona=1

I think that i have to mix some mysql querys to get the total.

With this query i can get the difference between two dates, but i don't know how to set start and end dates with the data of the same column('fecha')

SELECT TIMESTAMPDIFF(MONTH, start, end)
select 
  date_format(dt, '%Y-%m-01') each_months_start,
  sec_to_time(sum(secs)) sums_of_secs
from (
  select date(fetcha) dt, time_to_sec(timediff(max(fetcha), min(fetcha))) secs
  from my_table
  group by date(fetcha)
) t
group by
  date_format(dt, '%Y-%m-01');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM