niXforums Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   PreferencesPreferences   Log in to check your private messagesLog in to check your private messages   Log inLog in 
· nixdoc.net · man pages · Linux HOWTOs · FreeBSD Tips · Forums
navigation Forum index » Databases » IBM DB2
Querying for Third Shift
Post new topic   Reply to topic Page 1 of 1 [5 Posts] View previous topic :: View next topic
Author Message
dmeiser
*nix forums beginner


Joined: 20 May 2006
Posts: 7

PostPosted: Wed Jul 12, 2006 12:50 pm    Post subject: Querying for Third Shift Reply with quote

Hello all:

I need to query a table for events that happen on third shift ( 11 PM
to 7 AM ) in a date range. In the past, I've only needed to query for
one night, but I now need to query for 14 days. Normally, I would say
WHEN Col BETWEEN TimeStamp1 And TimeStamp2, but obviously that won't
work in this case.

For first shift I was able to do WHEN DateCol BETWEEN Date1 And Date2
AND WHEN TimeCol BETWEEN Time1 AND Time2, but for third shift this
obviously won't work.

I could use two different queries and, for third shift, say WHEN ...
AND TimeCol BETWEEN Time1 AND 11:59:59 and then UNION it with WHEN
TimeCol BETWEEN 00:00:00 AND Time2. However, since this will be linked
into an MS Access report, I'd prefer not to have to maintain two
different reports and copy the report back and forth if I make a change
to the SQL or report layout.

Is there any way to do this without either a UNION query or an SQL
function?

Thanks for any help.
Back to top
s.sathyaram@googlemail.co
*nix forums beginner


Joined: 20 Feb 2006
Posts: 13

PostPosted: Wed Jul 12, 2006 1:19 pm    Post subject: Re: Querying for Third Shift Reply with quote

How about

col between timestamp1 and timestamp2 and (time(col) > 2300 or
time(col) < 0700)

Sathyaram
Back to top
dmeiser
*nix forums beginner


Joined: 20 May 2006
Posts: 7

PostPosted: Wed Jul 12, 2006 2:07 pm    Post subject: Re: Querying for Third Shift Reply with quote

I thought this might work, but then I realized I had left something
out: I'm selecting a maximum and minimum time for an event for each
business day in the two week period.

Since our business day starts the previous day at about 11:00 PM
(really, whenever third shifters start), the minimum time for that
business day might be 11:15 PM the previous day, while the maximum time
might be 6:30 AM on the actual day. The whole reason behind getting
the maximum and minimum times is to figure out the time difference
between them.

Perhaps I do need two queries: one with performing a union between
times > 11:00 PM Times < 7:00 AM and the second for day shifters?

Sathyaram Sannasi wrote:
Quote:
How about

col between timestamp1 and timestamp2 and (time(col) > 2300 or
time(col) < 0700)

Sathyaram
Back to top
Chris
*nix forums beginner


Joined: 10 Nov 2005
Posts: 23

PostPosted: Wed Jul 12, 2006 3:29 pm    Post subject: Re: Querying for Third Shift Reply with quote

dmeiser wrote:
Quote:
...
Since our business day starts the previous day at about 11:00 PM
(really, whenever third shifters start), the minimum time for that
business day might be 11:15 PM the previous day, while the maximum time
might be 6:30 AM on the actual day. The whole reason behind getting
the maximum and minimum times is to figure out the time difference
between them.


If you have a timestamp column containing this information (as opposed
or in addition to a broken out date and time columns), then Sathyaram's
solution will work as he wrote it - the first part of the query can
take care of the overlapping dates. If the dates are broken out, then
the union might work best.

If you have timestamps, you can rewrite Sathyaram's query to do this by
using between, too. Use:

col between timestamp1 and timestamp2 and (time(col + 8 hours) between
0700 and
and 1500)

-Chris
Back to top
dmeiser
*nix forums beginner


Joined: 20 May 2006
Posts: 7

PostPosted: Thu Jul 20, 2006 12:08 pm    Post subject: Re: Querying for Third Shift Reply with quote

I realized how to do this after some time by doing the following:

Select column1, sum(column2), Max(Time), Min(Time), From (
Select column1, column2, time from file where time <= midnight
Union Select column1, column2, time from file where time >= midnight
and time <= 7:00 AM
) Group By column1 Order by column1
Back to top
Google

Back to top
Display posts from previous:   
Post new topic   Reply to topic Page 1 of 1 [5 Posts] View previous topic :: View next topic
The time now is Fri Jul 30, 2010 2:57 am | All times are GMT
navigation Forum index » Databases » IBM DB2
Jump to:  

Similar Topics
Topic Author Forum Replies Last Post
No new posts RAID, mdadm shift dev point Andrea Ganduglia Debian 4 Mon Jul 17, 2006 3:30 pm
No new posts which database is best for match querying monomaniac21 PHP 4 Sat Jul 08, 2006 10:27 pm
No new posts Shift operators. deepak C 9 Wed Jun 14, 2006 11:12 am
No new posts shift a block of memory content yancheng.cheok@gmail.com C 7 Sun Jun 11, 2006 6:47 am
No new posts KOrganizer time shift and other things with 10.1 John Bowling Suse 0 Fri Jun 09, 2006 4:21 pm

Copyright © 2004-2005 DeniX Solutions SRL   Other DeniX Solutions sites: Unix/Linux blog |  electronics forum |  medicine forum |  science forum |  Privacy Policy



Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0692s ][ Queries: 14 (0.0404s) ][ GZIP on - Debug on ]