If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Long time no SQL

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-12-07, 05:08
oneleg_theone oneleg_theone is offline
Registered User
 
Join Date: Jul 2003
Posts: 123
Long time no SQL

Seems like I'm a bit rusty at SQL... I can't see why this code doesnt work.

I have an eventlog in my system that registers all events from various units.
What I want to do is select all units that hasn't had any events in a specific interval. Say 2 hours.

First I created a query that selects max(time) from the log, I then want to select just the units with no events in the interval. It returns none although I know there should be some rows if I look at the inner query.

select a.MAXTIME, a.unitid
from
(select max(`Time`) as MAXTIME, unitid from eventlog group by unitid) a
where
(a.MAXTIME < (Now() - INTERVAL 120 MINUTE))

I'd very much lie this task to be done in ONE query, but maybe it isn't possible?

EDIT: OMG.... I had written the wrong date for today in the time column.... I had written tomorrow. Query works ok if I changed the date!
*puts on funny hat and sits in corner ashamed*

Last edited by oneleg_theone; 07-12-07 at 05:16.
Reply With Quote
  #2 (permalink)  
Old 07-12-07, 09:37
aschk aschk is offline
Registered User
 
Join Date: Mar 2007
Location: 636f6d7075746572
Posts: 770
LOL, it happens
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On