Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5844789
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:20:33+00:00 2026-05-22T12:20:33+00:00

I am trying to design a database for creating a school syllabus. In a

  • 0

I am trying to design a database for creating a school syllabus. In a nutshell, all classrooms can be active for 10 hours from 8.00am to 18.00 pm. How to create the database to answer the below ?

Get me empty hours for the classroom which is A101 on Monday ?

I made this one below but its not enough good to answer this question efficiently |:
http://i51.tinypic.com/110drgk.png

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T12:20:34+00:00Added an answer on May 22, 2026 at 12:20 pm

    I only dabble in database, but the problem seemed interesting to me.

    From what I’m getting, it sounds like you are more interested in how to write the query than how to store the data. Based on your explanation, what you want is a query whose output looks something like this:

    classroom  openStart  openEnd  day session
    A101       9:00       10:00    mo  spring
    A101       14:00      16:00    mo  spring
    

    Assuming schema test, table class. Class holds a startTime and endTime value. Other values on which filtering will be performed are ignored here to focus on just the logic you are interested in. This query was run on MySQL.

    -- 8 and 18 are added as the boundaries for the day.
    Select * from (Select * from ((select endTime as a from test.class) union (select 8)) as t1 
       join ((select startTime as b from test.class) union (select 18 as startTime)) as t2 
       where a <= b group by a order by a, b) as t3 where a != b;
    

    Three subqueries.

    The first creates a cross-product of all end times (with the start time for the day appended) by all start times (with the end time for the day appended in). What this gives you is a series of rows representing every conceivable open block of time. (arranged as block start/ block end)

    The second then pares the results of the first subquery by filtering out values where block start happens after block end, then sorts the values by block start, block end. This makes it so that when the values are grouped by block-start, you get a nice list of pairs that make it easy to spot places where classes are continuous.

    The third query then filters out the values where the times are the same, giving you just the time blocks that are relevant. Hypothetically the third query could use a comparison that ruled out cases where classes were less than an hour apart as well.

    I’m sure others might have somewhat simpler solutions for you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to design a database for a sports meeting. I think I've got
I've been trying to design a database schema for a side project but I
I am trying to so something like Database Design for Tagging , except each
I am trying to find the best way to design the database in order
I am trying to design a location lookup in which the user can specify
I'm trying to design a MySQL database to store user zipcode preferences for providing
I am trying to design a simple SQLite database to bill players on a
I'm trying to design some tables to store some data, which has to be
I'm trying to design an application based on the OpenSocial API , and I'm
I'm trying to design a model for a application allowing 2 people to bet

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.