sql - Sum of time differences of unknown number of rows in mysql -


i need sum of times difference of unknown number of date rows. can sum of list using,

select sec_to_time(sum(time(o.discontinued_date))).

but need sum of time differences. example,

2014-09-24 01:17:28 2014-09-24 01:17:41 2014-09-24 01:17:48 

answer list should 00:00:20

but in case not know number of rows. not know should sum of differences. please help. sorry english. if need more details please comment. thank you

if understood correctly.. doesn't matter whether have 2 rows or 20, since intrested in smallest , biggest time.

so query should simple:

select max(discontinued_date) - min(discontinued_date) yourtable; 

in case want each id/day or dont know, should use group this:(i.e. sum per day)

select discontinued_date,max(discontinued_date) - min(discontinued_date) yourtable group discontinued_date; 

Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -