queries on structured data?

This is a discussion on queries on structured data? within the MySQL Database forums, part of the Database Forums category; Hi, I am working for a college. The campus calendar [classes start/end, vacation start/end, etc] is available to ...


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 07-27-2007
seven.reeds
 
Posts: n/a
Default queries on structured data?

Hi,

I am working for a college. The campus calendar [classes start/end,
vacation start/end, etc] is available to me as an RSS feed. All I
can do is read this data, I can not "query" it. I have a small app
that reads the RSS feed and populates a local table with the RSS info.
This table I can query. The local table looks like:

CREATE TABLE `academic_calendar` (
`id` int(10) unsigned NOT NULL auto_increment,
`date` datetime NOT NULL,
`title` varchar(128) NOT NULL,
`category` varchar(128) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `event` (`date`,`title`,`category`)
)

The records either identify the start/end of a semester or multi-day
break or single day "breaks" or special occasions. My only clues
are in the event titles:

First Day of Class, Fall Semester
Labor Day
Thanksgiving Vacation Begins
Class Resumes
Class Ends for Fall Semester
Final Exams
First Day of Class, Spring Semester
Martin Luther King Day
Spring Vacation Begins
Class Resumes
Class Ends for Spring Semester
... etc ...

I want to do queries on this data that will either be for date=NOW()
or
date=<some future date>. I want to ask questions like:

- is date-X in the Fall 2007 semester?

- what semester is date-X in?

- is date-X a class-day, i.e. is it in a semester but not in a
vacation range or other holiday

- is date-X in a vacation range or is it a holiday

My first attempt to answer "is date-X in the Fall 2007 semester?" was:

SELECT * FROM `academic_calendar`
WHERE `date` BETWEEN(
(SELECT `date` FROM `academic_calendar`
WHERE `title` = 'First Day of Class, Fall Semester'
AND YEAR(`date`) = '2007'),
(SELECT `date` FROM `academic_calendar`
WHERE `title` = 'Class Ends for Fall Semester'
AND YEAR(`date`) = '2007'))

but there is a syntax error. I'm not seeing it unless these
sub-selects are just not allowed here.

Basically, how do I deal with queries on data that is structured
in this way? There are Start/End records and singleton records.
There are Start/End records that "enclose" other records.

I can imagine selecting all future records and then processing them
in my app to find start/end records. Is that the best way to go?
Can DB queries do what I want?

Reply With Quote
  #2 (permalink)  
Old 07-27-2007
seven.reeds
 
Posts: n/a
Default Re: queries on structured data?

That select above does not like the BETWEEN. I changed it to:

SELECT * FROM `academic_calendar`
WHERE `date` >=
(SELECT `date` FROM `academic_calendar`
WHERE `title` = 'First Day of Class, Fall Semester'
AND YEAR(`date`) = '2007')
AND `date` <=
(SELECT `date` FROM `academic_calendar`
WHERE `title` = 'Class Ends for Fall Semester'
AND YEAR(`date`) = '2007')

and it was fine

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 09:18 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0