×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Table with "starting date" for data

Table with "starting date" for data

Table with "starting date" for data

(OP)
Hi all.

Suppose we have a table PLAYER_TEAM which stores the team (TEAM_ID) a player (PLAYER_ID) plays for, starting from a given date (STARTING_DATE). So we have something like this:

CODE

PLAYER_ID   TEAM_ID    STARTING_DATE
---------   -------    -------------
   1           1        20/10/2008
   1           3        11/12/2008
   1           2        08/01/2009
   1           1        25/03/2009

Player 1 plays for team 1 between 20/10/2008 and 10/12/2008, for team 3 between 11/12/2008 and 07/01/2009, for team 2 between 08/01/2009 and 24/03/2009, and again for team 1 from 25/03/2009.

I can make a query that, given a particular date and player, determine the team he was playing for.

But i'd like to have a query to make a view with the relation between players, teams and starting and finishing date.

CODE

PLAYER_ID   TEAM_ID    STARTING_DATE    ENDING_DATE
---------   -------    -------------    -----------
   1           1        20/10/2008       11/12/2008
   1           3        11/12/2008       08/01/2009
   1           2        08/01/2009       25/03/2009
   1           1        25/03/2009         (null)

I thought it would be easier, but i couldn't find a way.

I would add the ending_date column to the table, but it requires a more difficult management (when inserting and specially modifying dates).

Thanks in advance.
Fred.

RE: Table with "starting date" for data

(OP)
Well, i think i have it. It was easier than i thought.

CODE

select a.player_id, a.team_id, a.starting_date, min(b.starting_date)
from player_team a
left outer join player_team b
on a.player_id = b.player_id
and b.starting_date > a.starting_date
group by a.player_id, a.team_id, a.starting_date
order by a.player_id, a.starting_date

Thanks anyway.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close