Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Database Theory > Avoiding an inl...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 4 Topic 2522 of 2612
Post > Topic >>

Avoiding an inline view using DML only

by Morten <usenet@[EMAIL PROTECTED] > Apr 23, 2008 at 05:22 AM

Hi.

A user enters a date range (ie. 2 dates, '2008-04-01' and
'2008-04-03'), the problem is to determine how many open events exist
on each day in this interval.

Assume that the "events" table has a "start_date" and an "end_date".
One way to solve this problem, is to create an inline view in the
query, eg.:

SELECT virtual_date_range.index_date AS index_date, COUNT(*) AS
matches
FROM events, (
  SELECT DATE('2008-04-01') AS index_date FROM DUAL UNION ALL
  SELECT DATE('2008-04-02') FROM DUAL UNION ALL
  SELECT DATE('2008-04-03') FROM DUAL UNION ALL
)  AS virtual_date_range
WHERE virtual_date_range.index_date >= events.start_date
AND      virtual_date_range.index_date <= events.end_date
GROUP BY index_date;

This works. But I'm wondering if there's a more elegant way of
expressing the same using pure DML, such that I don't need to build a
huge inline view in case the range is multiple years.

A solution that doesn't return any rows for the dates that do not have
an event would work.
Example of the events table and the above query in action:
http://www.pastie.org/185419

Any tips greatly appreciated, thanks.

Morten




 4 Posts in Topic:
Avoiding an inline view using DML only
Morten <usenet@[EMAIL   2008-04-23 05:22:46 
Re: Avoiding an inline view using DML only
Carl Federl <cfederl@[  2008-04-23 13:00:19 
Re: Avoiding an inline view using DML only
"David Cressey"  2008-04-24 09:59:19 
Re: Avoiding an inline view using DML only
MoMorten <usenet@[EMAI  2008-04-24 06:01:04 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan13V112 Fri Jul 4 16:07:36 CDT 2008.