开发者

Average between two columns in mysql that are date not timestamp

开发者 https://www.devze.com 2023-01-19 22:13 出处:网络
Alright so here it is. I need to figure out the average amount of days between two columns. Column 1 is recieved_date and column 2 is fix_date

Alright so here it is. I need to figure out the average amount of days between two columns.

Column 1 is recieved_date and column 2 is fix_date

Just want to know how to take the 开发者_如何学Gotwo dates find the difference in days, do that for every row and pop out a number stating the average amount of days it takes to fix something.

Tried to find it online but every time I find something like it, they have two specific dates. I need the entire columns averaged.


You can use the TIMESTAMPDIFF function both for dates and datetime.

See Mysql average time between visits


Add a group by and some other columns to this and it should do the trick:

select 
  avg(fix_period)
from
(
select
  datediff(fix_date, received_date) as fix_period
  from some_table
) as a
;
0

精彩评论

暂无评论...
验证码 换一张
取 消