Connecting Tech Pros Worldwide Help | Site Map

Search rows back in table mysql

Familiar Sight
 
Join Date: Oct 2007
Posts: 254
#1: 4 Weeks Ago
Hi everyone.

My table mysql is:

Expand|Select|Wrap|Line Numbers
  1. ID    Dist     Date         Hour
  2. 15    LT     22/10/2009     08:56:05 
  3. 14    RM     22/10/2009     08:55:20  
  4. 13    RM     22/10/2009     08:55:19  
  5. 12    RM     22/10/2009     08:51:22    
  6. 11    LT     22/10/2009     08:47:19
  7.  
I try this query and working:

Expand|Select|Wrap|Line Numbers
  1. SELECT 
  2. TIMEDIFF(b.hour, a.hour) AS strDiff 
  3. FROM doTbl_A a JOIN
  4. doTbl_A b ON 
  5. a.ID=b.id-1 OR
  6. a.ID=b.id-2 OR
  7. a.ID=b.id-3 OR
  8. A.ID=b.id-4
  9. WHERE a.DIST=b.DIST 
  10. 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's Avatar
Moderator
 
Join Date: Nov 2006
Location: Iceland
Posts: 3,745
#2: 4 Weeks Ago

re: Search rows back in table mysql


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)
Familiar Sight
 
Join Date: Oct 2007
Posts: 254
#3: 4 Weeks Ago

re: Search rows back in table mysql


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:

Expand|Select|Wrap|Line Numbers
  1. ID    Dist     Date         Hour
  2. 15    LT     22/10/2009     08:56:05 
  3. 14    RM     22/10/2009     08:55:20  
  4. 13    RM     22/10/2009     08:55:19  
  5. 12    RM     22/10/2009     08:51:22    
  6. 11    LT     22/10/2009     08:47:19 
  7.  
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?
Reply