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 7531997
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:19:30+00:00 2026-05-30T05:19:30+00:00

I have this existing schema where a schedule table looks like this (very simplified).

  • 0

I have this existing schema where a “schedule” table looks like this (very simplified).

CREATE TABLE schedule (
  id           int(11) NOT NULL AUTO_INCREMENT,
  name         varchar(45),
  start_date   date,
  availability int(3),
  PRIMARY KEY (id)
);

For each person it specifies a start date and percentage of work time available to spent on this project. That availability percentage implicitly continues until a newer value is specified.
For example take a project that lasts from 2012-02-27 to 2012-03-02:

id | name | start_date | availability
-------------------------------------
 1 |  Tom | 2012-02-27 |          100 
 2 |  Tom | 2012-02-29 |           50
 3 |  Ben | 2012-03-01 |           80

So Tom starts on Feb., 27nd, full time, until Feb, 29th, from which on he’ll be available only with 50% of his work time.
Ben only starts on March, 1st and only with 80% of his time.

Now the goal is to “normalize” this sparse data, so that there is a result row for each person for each day with the availability coming from the last specified day:

name | start_date | availability
--------------------------------
 Tom | 2012-02-27 |          100 
 Tom | 2012-02-28 |          100
 Tom | 2012-02-29 |           50
 Tom | 2012-03-01 |           50
 Tom | 2012-03-02 |           50
 Ben | 2012-02-27 |            0 
 Ben | 2012-02-28 |            0
 Ben | 2012-02-29 |            0
 Ben | 2012-03-01 |           80
 Ben | 2012-03-02 |           80

Think a chart showing the availability of each person over time, or calculating the “resource” values in a burndown diagram.
I can easily do this with procedural code in the app layer, but would prefer a nicer, faster solution.

  • 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-30T05:19:32+00:00Added an answer on May 30, 2026 at 5:19 am

    To make this remotely effective, I recommend creating a calendar table. One that contains each and every date of interest. You then use that as a template on which to join your data.

    Equally, things improve further if you have person table to act as the template for the name dimension of your results.

    You can then use a correlated sub-query in your join, to pick which record in Schedule matches the calendar, person template you have created.

    SELECT
      *
    FROM
      calendar
    CROSS JOIN
      person
    LEFT JOIN
      schedule
        ON  schedule.name       = person.name
        AND schedule.start_date = (SELECT MAX(start_date)
                                     FROM schedule
                                    WHERE name = person.name
                                      AND start_date <= calendar.date)
    WHERE
          calendar.date >= <yourStartDate>
      AND calendar.date <= <yourEndDate>
      etc
    

    Often, however, it is more efficient to deal with it in one of two other ways…

    Don’t allow gaps in the data in the first place. Have a nightly batch process, or some other business logic that ensures all relevant dat apoints are populated.

    Or deal with it in your client. Return each dimension in you report (data, and name) as seperate data sets to act as your templates, and then return the data as your final data set. Your client can itterate over the data and fill in the blanks as appropriate. It’s more code, but can actually use less resource overall than trying to fill-the-gaps with SQL.

    (If your client side code does this slowly, post another question examining that code. Provided that the data is sorted, this is acutally quite quick to do in most languages.)

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

Sidebar

Related Questions

I have an existing table structure that looks something like this: AnimalTable ------------- |Id
Assuming I have an SQL table with this schema: CREATE TABLE( foo INTEGER, bar
I have a sql-file containing several statements like this: create table user ( name
Some existing web services I consume have methods that look something like this: List<Employee>
I have the following schema (generated from an existing table with the schema module
I have an existing XML schema that contains a type that I would like
I have the following table schema: create table SerialNo2( IncarnationID_UID counter primary key, Mark
I have the following existing DB schema, which I'd like to recreate with Java
Let's say I have a table like this (ordered by id ): id amount
I have an existing application that is written in C++ for Windows. This application

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.