473,770 Members | 1,989 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Please explain query intervals output

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....m-db2/200810/1

Oct 3 '08 #1
1 1779
On 3 Okt, 14:42, "lenygold via DBMonster.com" <u41482@uwewrot e:
[...]
>
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
Oct 3 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
3699
by: KULJEET | last post by:
i have a table with following data qty start_no end_no 1 1 100 1 101 200 1 201 300 1 5001 5100 1 7001 7100 1 7101 7200 i used query like
0
1223
by: Brady Orand | last post by:
I have a table with the following description: user varchar(64) outtime datetime intime datetime <other irrelevant columns> I want to query this table from datetime1 to datetime2 at consistent intervals. Unfortunately, the data is not in consistent intervals.
9
2414
by: hope | last post by:
Hi Access 97 I'm lost on this code please can you help ================================= Below is some simple code that will concatenate a single field's value from multiple records into a single string separated by a user defined character. There is no error trapping (by design), USE AT YOUR OWN RISK.
5
1590
by: jag | last post by:
Hi i have a drill hole geology table with information as follows holeid depthfrom depth to plot1 hwrc1 0 1 cuf hwrc1 1 2 cuf hwrc1 2 4 cup hwrc1 4 6 cuf
2
2206
by: ormy28 | last post by:
I really need some help with the following problem if anyone would be willing. I need a list box to list the opposite of what appears in a query. Heres the details: My database is for a doctors surgery, and this includes the tables tblPatients, tblDoctors and tblAppointments. tblAppointments has an Appointment ID and also includes the Patient ID (from tblPatient) and Doctor ID (from tblDoctor) plus the start and end time of the
9
2107
by: colin.mcnulty | last post by:
Hi, I'm a SQL Server DBA, but I guess that won't buy me any friends round here huh? ;-) I've been asked to look at the SQL that's being executed on a DB2 database from a web app, specifically when the web site does XYZ, what SQL does it run on the DB2 database? Unfortunately everyone who knew about how it works has left and I've never even seen a DB2 database before today! So, I appear to be looking at an IBM DB2 Universal Database...
10
1275
by: Bishman | last post by:
Hi, I have a form application that needs to query a DB at a set timed interval and then refresh the form with values received from the DB. Simple enough. My design releated questions are .... Should I create a worker thread that encapsulates a timer, (which I believe will also create a seperate thread when the timer fires) , or should I create a timer that creates a new thread when it fires ? Or neither ?
0
1996
by: plaidthermos | last post by:
hello, i have a database where there is a main table, documents, and then a relationship table doc_topics with one entry for each topic into which a document falls. (any document may have an arbitrary number of topics, but always at least one.) this structure is repeated for other relationships such as doc_states, doc_types, et cetera. i want a query that uses one or more of the relationships as search criteria (example, return only...
5
8108
by: kabotnet | last post by:
Hi, I'm new in db2, I'm trying to execute EXPLAIN command on some queries but i have error like: And message similar to: Token EXPLAIN is not valid, valid tokens ( END GET SET CALL DROP FREE HOLD LOCK OPEN WITH ALTER. I've created tables explain_* How can I start to find solution? Is it possible that my db2 doesn't support explain?
0
9618
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10259
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10101
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10038
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9906
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7456
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2849
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.