Search rows back in table mysql

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • viki1967
    Contributor
    • Oct 2007
    • 263

    Search rows back in table mysql

    Hi everyone.

    My table mysql is:

    Code:
    ID	Dist 	Date	 	Hour
    15	LT 	22/10/2009 	08:56:05 
    14	RM 	22/10/2009 	08:55:20  
    13	RM 	22/10/2009 	08:55:19  
    12	RM 	22/10/2009 	08:51:22    
    11	LT 	22/10/2009 	08:47:19
    I try this query and working:

    Code:
    SELECT 
    TIMEDIFF(b.hour, a.hour) AS strDiff 
    FROM doTbl_A a JOIN
    doTbl_A b ON 
    a.ID=b.id-1 OR
    a.ID=b.id-2 OR
    a.ID=b.id-3 OR
    A.ID=b.id-4
    WHERE a.DIST=b.DIST 
    AND a.DATE=b.DATE ORDER BY a.ID
    But I do not know the exact location of the rows... can you help me?
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hey.

    Could you explain that a little better?

    What exactly are you expecting to happen?
    What is actually happening?

    P.S.
    Be careful with your names. Both 'date' and 'hour' are reserved MySQL keywords, so it is not a good idea to use them as column names. Even tho it may not be a problem in certain situations, it may be in others.

    If you do use them, it is best to enclose them in back-ticks (`). That way you can be sure they aren't causing problems.

    Also, it is best to always write out database, table and column names is their proper case. In certain situations, 'A' is not the same as 'a'. Best to keep it consistent, and always use one or the other. (See line #8 in the query you posted)

    Comment

    • viki1967
      Contributor
      • Oct 2007
      • 263

      #3
      Atli:

      I need showing a time difference between rows.

      If a.DIST=b.DIST and a.DATE=b.DATE and strDiff is < 1 hour I need show the rows.

      This is my table:

      Code:
      ID	Dist 	Date	 	Hour
      15	LT 	22/10/2009 	08:56:05 
      14	RM 	22/10/2009 	08:55:20  
      13	RM 	22/10/2009 	08:55:19  
      12	RM 	22/10/2009 	08:51:22    
      11	LT 	22/10/2009 	08:47:19
      The difference 08:56:05 (ID=15) and 08:47:19 (ID=11) is < 1 hour... only ID=11 is valid, ID=15 is not valid...

      In the table mysql I do not know the exact location of the rows ...

      You understand me?

      Comment

      Working...