Sum of time differences of unknown number of rows in mysql

Choxmi

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

sagi

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]

編集
0

コメントを追加

0

関連記事

分類Dev

MySQL Calculating sum over pairwise time differences of log file

分類Dev

Sum time differences across multiple timezones in PostgreSQL

分類Dev

Limit sum of rows in MySQL

分類Dev

SUM() function differences between SQL Server and MySQL

分類Dev

datatables serverside processing with unknown number of rows

分類Dev

Sum over rows (rollapply) with time decay

分類Dev

Mysql query based on unknown number of parameters

分類Dev

python loop through number of rows at a time

分類Dev

FInd number of rows in given time window in Pyspark

分類Dev

golang mysql store arbitary number of rows in structure

分類Dev

GROUP BY the number of rows returned by GROUP BY in MySQL

分類Dev

MySQL Select WHERE IN and LIMIT by number of rows

分類Dev

Limit the max number of rows in column MySQL

分類Dev

MySQL group rows to find time difference

分類Dev

"If the number is contained in the text and is repeated, return the sum of the number for each time it is repeated. Otherwise return 0."

分類Dev

How to get number of rows by select query using mysql

分類Dev

Is there a limit on the number of rows I can update via an IN clause of a MySQL query?

分類Dev

MySQL correct statement for "update all rows where column > number"?

分類Dev

How to count number of rows in other tables using mysql inner join?

分類Dev

Sum function with join is giving sum multiplies number of times of entries in laravel ORM with mysql

分類Dev

Angular Datatable >> How to get total number of rows and sum of the all amount values

分類Dev

argparse for unknown number of arguments and unknown names

分類Dev

Sum of differences over a JSONB array field in CockroachDB

分類Dev

MySQL: Select query execution and result fetch time increases with number of connections

分類Dev

Cumulative sum for duplicate rows

分類Dev

How to find number of rows that fall within a time period of each row, while satisfying criteria in other columns?

分類Dev

Differences between complex number implementations in Haskell and Python

分類Dev

Factorial as a sum of consecutive number

分類Dev

Sum of number in brainfuck

Related 関連記事

  1. 1

    MySQL Calculating sum over pairwise time differences of log file

  2. 2

    Sum time differences across multiple timezones in PostgreSQL

  3. 3

    Limit sum of rows in MySQL

  4. 4

    SUM() function differences between SQL Server and MySQL

  5. 5

    datatables serverside processing with unknown number of rows

  6. 6

    Sum over rows (rollapply) with time decay

  7. 7

    Mysql query based on unknown number of parameters

  8. 8

    python loop through number of rows at a time

  9. 9

    FInd number of rows in given time window in Pyspark

  10. 10

    golang mysql store arbitary number of rows in structure

  11. 11

    GROUP BY the number of rows returned by GROUP BY in MySQL

  12. 12

    MySQL Select WHERE IN and LIMIT by number of rows

  13. 13

    Limit the max number of rows in column MySQL

  14. 14

    MySQL group rows to find time difference

  15. 15

    "If the number is contained in the text and is repeated, return the sum of the number for each time it is repeated. Otherwise return 0."

  16. 16

    How to get number of rows by select query using mysql

  17. 17

    Is there a limit on the number of rows I can update via an IN clause of a MySQL query?

  18. 18

    MySQL correct statement for "update all rows where column > number"?

  19. 19

    How to count number of rows in other tables using mysql inner join?

  20. 20

    Sum function with join is giving sum multiplies number of times of entries in laravel ORM with mysql

  21. 21

    Angular Datatable >> How to get total number of rows and sum of the all amount values

  22. 22

    argparse for unknown number of arguments and unknown names

  23. 23

    Sum of differences over a JSONB array field in CockroachDB

  24. 24

    MySQL: Select query execution and result fetch time increases with number of connections

  25. 25

    Cumulative sum for duplicate rows

  26. 26

    How to find number of rows that fall within a time period of each row, while satisfying criteria in other columns?

  27. 27

    Differences between complex number implementations in Haskell and Python

  28. 28

    Factorial as a sum of consecutive number

  29. 29

    Sum of number in brainfuck

ホットタグ

アーカイブ