Re: finding continuous range

From: Jan Hidders <hidders_at_REMOVE.THIS.win.tue.nl>
Date: 12 May 2001 20:03:45 GMT
Message-ID: <9dk4v1$810$1_at_news.tue.nl>


harakiri wrote:
>
> "Jan Hidders" <hidders_at_REMOVE.THIS.win.tue.nl> wrote in message
> news:9dhjap$6g9$1_at_news.tue.nl...
>
> > SELECT sd1.startdate, ed1.enddate
> > FROM startdates AS sd1, enddates AS ed1
> > WHERE NOT EXISTS (
> > SELECT *
> > FROM enddates AS ed2
> > WHERE ed2.enddate BETWEEN sd1.startdate AND ed1.enddate
> > AND NOT EXISTS (
> > SELECT *
> > FROM schedules AS sc
> > WHERE sc.startdate <= ed2.enddate
> > AND sc.enddate > ed2.enddate
> > )
> > );
>
> Hmm... That's pretty much like "frequent drinker example" from Victor
> Vianu's "Databases and Finite-Model Theory" paper I read yesterday. He
> explaines that ordinary SQL statement is essentially:
>
> {x1:A1,...,xn:An | exists u (L1&...&Lk) }
>
> so that one have to unfold the query into a sequence of existentially
> quantified nested queries like you did.

Yup, SQL is basically equal to tuple calculus. The article you mentioned, by the way, is an excellent article and Victor Vianu is one of the top researchers in database theory. If you have any questions, I'll be glad to help.  

> Now, in your original solution I don't see 2 levels of 'EXIST' and
> that makes me suspicious that it would work (I don't have SQL today
> at hand as well, but will test your corrected statement monday;-).

Ok. Let me know what other mistakes I made. :-)

> Unless you would be kind to explain where second EXISTS collapsed.

It doesn't. The query you cite above just computes all continuous periods. This is not the problem that started this thread but was raised by Vadim in his reply. So it solves a different but related problem.

-- 
  Jan Hidders
Received on Sat May 12 2001 - 22:03:45 CEST

Original text of this message