Go Back   Forum Care Forums > Development Reference Area > MySQL Discussion

Reply
 
LinkBack Thread Tools Display Modes
Troublesome Query with Linked Jobs in DB
Old
  (#1)
Idgarad
Guest
 
Posts: n/a
Default Troublesome Query with Linked Jobs in DB - 06-04-2007, 07:46 AM

The problem I am struggling with is I have a database of batch jobs,
very simple.

JOBNAME,START TIME, FINISH TIME

JOB1STOP;1/1/7 9:00:00;1/1/7 9:00:00
....
JOB1STOP;1/1/7 9:01:00;1/1/7 9:07:00
....
JOB1START;1/1/7 12:34:01;1/1/7 12:54:03
....
JOB1START;1/1/7 12:37:01;1/1/7 12:59:03

The reality of this is The JOB1STOP begins a database down for
maintenance and JOB1START begins it back up.

The second JOB1STOP doesn't matter (it's already down) nor does the
second JOB1START (it's already up) so I am guessing that a query in
psuedo-code would look like (***uming we want just jobs from 1/1/7:

SELECT (jobname,start time, finish time) from JOBTABLE where STARTTIME
like "1/1/7" AND JOBNAME like "START" or "STOP"

But then I have to figure out how to clip only the first STOP and the
FIRST START ignoring the duplicates. (distinct perhaps?)

Depending on the server the logs are from means I would invert the
criteria needing only the LAST of a given record. (order by prior to
distinct?)

I am not very good with complex SQL queries, but my best guess to this
point is (using $vars)

SELECT (jobname,start_time,end_time) from $TABLE
WHERE start_time >= "1/1/7" AND
jobname LIKE ("START" OR "STOP")
ORDER BY start_time DISTINCT

Am I close? and How could I ignore the query if one of the two are not
present (ignore STARTS or STOPS on a day that the other is missing?)

Id..

   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Re: Troublesome Query with Linked Jobs in DB
Old
  (#2)
Paul Lautman
Guest
 
Posts: n/a
Default Re: Troublesome Query with Linked Jobs in DB - 06-04-2007, 07:46 AM

Idgarad wrote:
> The problem I am struggling with is I have a database of batch jobs,
> very simple.
>
> JOBNAME,START TIME, FINISH TIME
>
> JOB1STOP;1/1/7 9:00:00;1/1/7 9:00:00
> ...
> JOB1STOP;1/1/7 9:01:00;1/1/7 9:07:00
> ...
> JOB1START;1/1/7 12:34:01;1/1/7 12:54:03
> ...
> JOB1START;1/1/7 12:37:01;1/1/7 12:59:03
>
> The reality of this is The JOB1STOP begins a database down for
> maintenance and JOB1START begins it back up.
>
> The second JOB1STOP doesn't matter (it's already down) nor does the
> second JOB1START (it's already up) so I am guessing that a query in
> psuedo-code would look like (***uming we want just jobs from 1/1/7:
>
> SELECT (jobname,start time, finish time) from JOBTABLE where STARTTIME
> like "1/1/7" AND JOBNAME like "START" or "STOP"
>
> But then I have to figure out how to clip only the first STOP and the
> FIRST START ignoring the duplicates. (distinct perhaps?)
>
> Depending on the server the logs are from means I would invert the
> criteria needing only the LAST of a given record. (order by prior to
> distinct?)
>
> I am not very good with complex SQL queries, but my best guess to this
> point is (using $vars)
>
> SELECT (jobname,start_time,end_time) from $TABLE
> WHERE start_time >= "1/1/7" AND
> jobname LIKE ("START" OR "STOP")
> ORDER BY start_time DISTINCT
>
> Am I close? and How could I ignore the query if one of the two are not
> present (ignore STARTS or STOPS on a day that the other is missing?)
>
> Id..


You need what I call the "Strawberry Query"
See the pattern for it in my response on this thread:
http://tinyurl.com/yex7s2


   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools
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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Contact Us - Forum Care Forums - Archive - Top