Welcome to dbFreaks.com!
FAQFAQ      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Please explain query intervals output

 
   Database Help (Home) -> DB2 RSS
Next:  Problems with External Php Extensions  
Author Message
lenygold via DBMonster.co

External


Since: Feb 19, 2008
Posts: 80



(Msg. 1) Posted: Fri Oct 03, 2008 9:42 am
Post subject: Please explain query intervals output
Archived from groups: comp>databases>ibm-db2 (more info?)

I found this query on older thread and i can not uderstand output interval
pairs:

How to find min and max values in date intervals:
--------------------------------------------------
Input:
CREATE TABLE INTERVALS
(key CHAR(5) NOT NULL
,level CHAR(7) NOT NULL
,date_from DATE NOT NULL
,date_to DATE NOT NULL
);

INSERT INTO INTERVALS
VALUES
('key1', 'level1', '2001-05-01', '2002-10-01')
,('key1', 'level1', '2001-01-01', '2001-04-30')
,('key1', 'level1', '2000-11-10', '2000-12-31')
,('key1', 'level1', '2000-06-01', '2000-10-09')
,('key1', 'level1', '2000-01-01', '2000-05-31')
;

SELECT l.key, l.level, l.date_from, r.date_to
FROM Intervals l
Intervals r,
WHERE NOT EXISTS
(SELECT *
FROM Intervals le
WHERE le.date_to = l.date_from - 1 DAY)
AND r.date_to =
(SELECT MIN(date_to)
FROM Intervals rm
WHERE rm.date_to > l.date_from
AND NOT EXISTS
(SELECT *
FROM Intervals re
WHERE re.date_from = rm.date_to + 1 DAY));

or

SELECT l.key, l.level, l.date_from
, (SELECT MIN(date_to)
FROM Intervals rm
WHERE rm.date_to > l.date_from
AND NOT EXISTS
(SELECT *
FROM Intervals re
WHERE re.date_from = rm.date_to + 1 DAY)
) AS date_to
FROM Intervals l
WHERE NOT EXISTS
(SELECT *
FROM Intervals le
WHERE le.date_to = l.date_from - 1 DAY);

Same output:

KEY LEVEL DATE_FROM DATE_TO
----- ------- ---------- ----------
key1 level1 2000-11-10 2002-10-01
key1 level1 2000-01-01 2000-10-09

2 record(s) selected.
What is the meaning of this output;
The min value in intervals are
2001-01-01
The max value in intervals are
2002-10-01
Please help
Thank's

--
Message posted via DBMonster.com
http://www.dbmonster.com/Uwe/Forums.aspx/ibm-db2/200810/1

 >> Stay informed about: Please explain query intervals output 
Back to top
Login to vote
Lennart

External


Since: Jan 11, 2008
Posts: 124



(Msg. 2) Posted: Fri Oct 03, 2008 9:42 am
Post subject: Re: Please explain query intervals output [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On 3 Okt, 14:42, "lenygold via DBMonster.com" <u41482@uwe> wrote:
[...]
>
> INSERT INTO INTERVALS
> VALUES
>  ('key1', 'level1', '2001-05-01', '2002-10-01')
> ,('key1', 'level1', '2001-01-01', '2001-04-30')
> ,('key1', 'level1', '2000-11-10', '2000-12-31')
> ,('key1', 'level1', '2000-06-01', '2000-10-09')
> ,('key1', 'level1', '2000-01-01', '2000-05-31')
> ;
>
[...]

> KEY   LEVEL   DATE_FROM  DATE_TO    
> ----- ------- ---------- ----------
> key1  level1  2000-11-10 2002-10-01
> key1  level1  2000-01-01 2000-10-09
>
>  2 record(s) selected.
> What is the meaning of this output;
> The min value in intervals are
> 2001-01-01
> The max value in intervals are
> 2002-10-01
> Please help
> Thank's
>

Not sure what you find confusing, but I think it will become clear to
you if you draw a timeline from '2000-01-01' to '2002-10-01' and then
put the intervals in the input ontop of that:

00-01-01..00-05-31
00-06-01..00-10-09
<--
> 00-11-10..00-12-31

01-01-01..

/Lennart

 >> Stay informed about: Please explain query intervals output 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
Delete explain plan question - DB2 V8 and V9 - Here's the statement: delete from table a where id1=4; Table a is a parent to table b,c,d,e,f,g,h,i,j,k,l Table a key is id1,id2 table b,c,d,e,f,g,h,i,j,k,l key is id2,id3. I delete all the rows from b,c,d,e,f,g,i,j,k,l before deleting the rows from..

ho w to see the output of "Message_Text" - Hi , I would like to know how to we see the output of "MESSAGE_TEXT " . Below is 1 such procedure .. create procedure mess_test (out p_sqlstate char(5) , out p_sqlcode int ) language sql specific mess_test begin declare v_count int; declare s...

Purging task output - Helpful folks, I have tasks defined in Task Center, on UDB V8.2 on Windows, that accumulate output at a rapid rate, and manually deleting them via the Journal is an arduous task. So to speak. Is it safe to simply run a job that deletes directly from..

What's the meaning of IID=0 in output of db2pd command - In output of comand "db2pd -d <dbname> -tcbstats index", what's the meaning of IID=0? Please advise. Thanks so much. James

increase the size of UNIX window to see the entire output .. - hi , I am running a " select " query on my DB2 Table ....which has around 45 columns ..from UNIX prompt . The query output is quiet staggered . Cant we set the window size to accomodate all the DB2 columns . Is their any way out to do that ....
   Database Help (Home) -> DB2 All times are: Pacific Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]