Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. A MySQL horror

A MySQL horror

Scheduled Pinned Locked Moved The Weird and The Wonderful
mysqlhelp
13 Posts 11 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Bernhard Hiller

    In a MySQL table, the start and en time of using a service are recorded. I tried to get the sum of usage per user and day:

    SELECT OriginationName, Date(StartTime), count(*), sum(timediff(endtime,starttime)) as duration
    FROM ippbxcdr
    Group by OriginationName, Date(StartTime)
    order by OriginationName, Date(StartTime)

    With a start time of '2012-08-21 15:02:29' and an end time of '2012-08-21 15:03:59', that duration of 1 minute 30 seconds was shown as 130.0000. No, no, no: thou shalt not use sum with timediff! The Lord of MySQL giveth no error message, he punisheth with a wrong result.

    B Offline
    B Offline
    Brisingr Aerowing
    wrote on last edited by
    #2

    X| :sigh: :doh: :wtf: :~ :omg: :(( :(

    I think computer viruses should count as life. I think it says something about human nature that the only form of life we have created so far is purely destructive. We've created life in our own image. Stephen Hawking

    1 Reply Last reply
    0
    • B Bernhard Hiller

      In a MySQL table, the start and en time of using a service are recorded. I tried to get the sum of usage per user and day:

      SELECT OriginationName, Date(StartTime), count(*), sum(timediff(endtime,starttime)) as duration
      FROM ippbxcdr
      Group by OriginationName, Date(StartTime)
      order by OriginationName, Date(StartTime)

      With a start time of '2012-08-21 15:02:29' and an end time of '2012-08-21 15:03:59', that duration of 1 minute 30 seconds was shown as 130.0000. No, no, no: thou shalt not use sum with timediff! The Lord of MySQL giveth no error message, he punisheth with a wrong result.

      B Offline
      B Offline
      Brady Kelly
      wrote on last edited by
      #3

      Ooouch!!! :omg:

      1 Reply Last reply
      0
      • B Bernhard Hiller

        In a MySQL table, the start and en time of using a service are recorded. I tried to get the sum of usage per user and day:

        SELECT OriginationName, Date(StartTime), count(*), sum(timediff(endtime,starttime)) as duration
        FROM ippbxcdr
        Group by OriginationName, Date(StartTime)
        order by OriginationName, Date(StartTime)

        With a start time of '2012-08-21 15:02:29' and an end time of '2012-08-21 15:03:59', that duration of 1 minute 30 seconds was shown as 130.0000. No, no, no: thou shalt not use sum with timediff! The Lord of MySQL giveth no error message, he punisheth with a wrong result.

        H Offline
        H Offline
        hussainnagri
        wrote on last edited by
        #4

        Horrifying

        1 Reply Last reply
        0
        • B Bernhard Hiller

          In a MySQL table, the start and en time of using a service are recorded. I tried to get the sum of usage per user and day:

          SELECT OriginationName, Date(StartTime), count(*), sum(timediff(endtime,starttime)) as duration
          FROM ippbxcdr
          Group by OriginationName, Date(StartTime)
          order by OriginationName, Date(StartTime)

          With a start time of '2012-08-21 15:02:29' and an end time of '2012-08-21 15:03:59', that duration of 1 minute 30 seconds was shown as 130.0000. No, no, no: thou shalt not use sum with timediff! The Lord of MySQL giveth no error message, he punisheth with a wrong result.

          F Offline
          F Offline
          Frans_55129
          wrote on last edited by
          #5

          ¿ Are you sure you haven't multiple records with the same values ? When you have 100 records with these values......you'll have this result.

          1 Reply Last reply
          0
          • B Bernhard Hiller

            In a MySQL table, the start and en time of using a service are recorded. I tried to get the sum of usage per user and day:

            SELECT OriginationName, Date(StartTime), count(*), sum(timediff(endtime,starttime)) as duration
            FROM ippbxcdr
            Group by OriginationName, Date(StartTime)
            order by OriginationName, Date(StartTime)

            With a start time of '2012-08-21 15:02:29' and an end time of '2012-08-21 15:03:59', that duration of 1 minute 30 seconds was shown as 130.0000. No, no, no: thou shalt not use sum with timediff! The Lord of MySQL giveth no error message, he punisheth with a wrong result.

            R Offline
            R Offline
            RafagaX
            wrote on last edited by
            #6

            Your punishment is accord to your sins, long live to our migthy and fair MySQL Lord! :laugh:

            CEO at: - Rafaga Systems - Para Facturas - Modern Components for the moment...

            1 Reply Last reply
            0
            • B Bernhard Hiller

              In a MySQL table, the start and en time of using a service are recorded. I tried to get the sum of usage per user and day:

              SELECT OriginationName, Date(StartTime), count(*), sum(timediff(endtime,starttime)) as duration
              FROM ippbxcdr
              Group by OriginationName, Date(StartTime)
              order by OriginationName, Date(StartTime)

              With a start time of '2012-08-21 15:02:29' and an end time of '2012-08-21 15:03:59', that duration of 1 minute 30 seconds was shown as 130.0000. No, no, no: thou shalt not use sum with timediff! The Lord of MySQL giveth no error message, he punisheth with a wrong result.

              M Offline
              M Offline
              Member_5893260
              wrote on last edited by
              #7

              I have renamed your thread appropriately!

              1 Reply Last reply
              0
              • B Bernhard Hiller

                In a MySQL table, the start and en time of using a service are recorded. I tried to get the sum of usage per user and day:

                SELECT OriginationName, Date(StartTime), count(*), sum(timediff(endtime,starttime)) as duration
                FROM ippbxcdr
                Group by OriginationName, Date(StartTime)
                order by OriginationName, Date(StartTime)

                With a start time of '2012-08-21 15:02:29' and an end time of '2012-08-21 15:03:59', that duration of 1 minute 30 seconds was shown as 130.0000. No, no, no: thou shalt not use sum with timediff! The Lord of MySQL giveth no error message, he punisheth with a wrong result.

                D Offline
                D Offline
                Dan Metheus
                wrote on last edited by
                #8

                You figured out to use timestampdiff(SECOND, time1, time2)?

                B 1 Reply Last reply
                0
                • B Bernhard Hiller

                  In a MySQL table, the start and en time of using a service are recorded. I tried to get the sum of usage per user and day:

                  SELECT OriginationName, Date(StartTime), count(*), sum(timediff(endtime,starttime)) as duration
                  FROM ippbxcdr
                  Group by OriginationName, Date(StartTime)
                  order by OriginationName, Date(StartTime)

                  With a start time of '2012-08-21 15:02:29' and an end time of '2012-08-21 15:03:59', that duration of 1 minute 30 seconds was shown as 130.0000. No, no, no: thou shalt not use sum with timediff! The Lord of MySQL giveth no error message, he punisheth with a wrong result.

                  M Offline
                  M Offline
                  Michael Kingsford Gray
                  wrote on last edited by
                  #9

                  Another good reason to buy SQL Server, or ORACLE, etc. Anyone who relies on MySql to run their vital business infrastructure deserves no less than burning at the stake.

                  F E 2 Replies Last reply
                  0
                  • D Dan Metheus

                    You figured out to use timestampdiff(SECOND, time1, time2)?

                    B Offline
                    B Offline
                    Bernhard Hiller
                    wrote on last edited by
                    #10

                    Yes, I found a solution:

                    SEC_TO_TIME( sum( time_to_sec(endtime)-time_to_sec(starttime))) as Duration

                    Looks complicated, but it works.

                    E 1 Reply Last reply
                    0
                    • M Michael Kingsford Gray

                      Another good reason to buy SQL Server, or ORACLE, etc. Anyone who relies on MySql to run their vital business infrastructure deserves no less than burning at the stake.

                      F Offline
                      F Offline
                      Florin Jurcovici
                      wrote on last edited by
                      #11

                      Michael K Gray wrote:

                      Another good reason to buy SQL Server, or ORACLE, etc.

                      That's plain wrong. It all depends on the business model and on the app using the database. Besides, MySQL does have its strengths - it beats any commercial offering from MS or Oracle when 90% of the workload is reads performed by a server with limited hardware (depending on the table type being used).

                      1 Reply Last reply
                      0
                      • B Bernhard Hiller

                        Yes, I found a solution:

                        SEC_TO_TIME( sum( time_to_sec(endtime)-time_to_sec(starttime))) as Duration

                        Looks complicated, but it works.

                        E Offline
                        E Offline
                        englebart
                        wrote on last edited by
                        #12

                        Maybe time diff is using some sort of fixed place BCD storage scheme. If you span a year does it produce a value out in the thousands? Something like: yyyymmddhhmmss or dddddddhhmmss I worked on a database once where dates were stored like: yyyymmdd. Everything collated correctly and it was easy to extract the field you wanted.

                        1 Reply Last reply
                        0
                        • M Michael Kingsford Gray

                          Another good reason to buy SQL Server, or ORACLE, etc. Anyone who relies on MySql to run their vital business infrastructure deserves no less than burning at the stake.

                          E Offline
                          E Offline
                          englebart
                          wrote on last edited by
                          #13

                          We have (for many years now) a worse problem in Or-ache-le. A query should return 3000 rows. It just returns 1200 and does not generate any error. A corrupted value in a key terminated the retrieval, but it still returned success.

                          1 Reply Last reply
                          0
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • World
                          • Users
                          • Groups