I need to get the sum of times difference of unknown number of date rows. I can get the sum of that list using,
SELECT SEC_TO_TIME(SUM(TIME(o.discontinued_date)))
.
But I need to get the sum of the time differences. As an example,
2014-09-24 01:17:28
2014-09-24 01:17:41
2014-09-24 01:17:48
answer for this list should be 00:00:20
But in my case I do not know the number of rows. I do not know what should I do to get the sum of differences. Please help. Sorry for my English. If you need more details please comment. Thank you
If I understood correctly.. it doesn't matter whether you have 2 rows or 20, since you are only intrested in the smallest and biggest time.
So you query should be very simple:
SELECT max(discontinued_date) - min(discontinued_date)
FROM YourTable;
In case you want to do it for each id/day or I dont know, you should use group by like this:(I.E. sum per day)
SELECT discontinued_date,max(discontinued_date) - min(discontinued_date)
FROM YourTable
GROUP BY discontinued_date;
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加