Subject | table design question |
---|---|
Author | George Smith |
Post date | 2002-12-04T19:46:58Z |
If we have a table name period:
Period:
Period_ID (PK)
Period_Desc eg Jan,Feb etc
Period_Start eg 01/01/02 02/01 etc
Period_End eg 01/31/02 02/28 etc
and we wish to be able to:
1. select individual month say Jan from table
2. Wish to define a collection of months let us say
FirstQuarter to select Jan,Feb,Mar
How do we go about it ? I tried to use two tables
Periods:
Periods_ID (PK)
Periods_Desc eg FirstQuarter
Period:
Period_ID (PK)
Periods_ID (FK)
Period_Desc eg Jan,Feb etc
Period_Start eg 01/01/02 02/01 etc
Period_End eg 01/31/02 02/28 etc
then I could populate the Period table with the Periods_ID
and the following would allow me to select FirstQuarter as follows:
SQL> select periods_desc,period_desc,period_start,period_end from
period,periods
where periods.periods_id = period.periods_id;
PERIODS_DESC PERIOD_DESC PERIOD_START PERIOD_END
=============== =============== ============ ===========
4TH Quarter DEC 2002-12-01 2002-12-31
4TH Quarter NOV 2002-11-01 2002-11-30
4TH Quarter OCT 2002-10-01 2002-10-31
============================================================================
====
SQL> select period_desc,period_start,period_end from period where
period.periods
_id = 7;
PERIOD_DESC PERIOD_START PERIOD_END
=============== ============ ===========
DEC 2002-12-01 2002-12-31
NOV 2002-11-01 2002-11-30
OCT 2002-10-01 2002-10-31
============================================================================
====
SQL> select * from period;
PERIOD_ID PERIODS_ID PERIOD_DESC PERIOD_START PERIOD_END
============ ============ =============== ============ ===========
1 7 DEC 2002-12-01 2002-12-31
2 7 NOV 2002-11-01 2002-11-30
3 7 OCT 2002-10-01 2002-10-31
4 <null> SEP 2002-09-01 2002-09-30
5 <null> AUG 2002-08-01 2002-08-31
6 <null> JUL 2002-07-01 2002-07-31
============================================================================
====
SQL> select * from periods;
PERIODS_ID PERIODS_DESC
============ ===============
7 4TH Quarter
What you want in an application is to have access to both the Periods and
the
Period table, that is you want to have a single period sometimes and other
times
to have access to a period that is made up of other periods. How is one
suppose
to do this in the RDBMS world ??
George R Smith
Period:
Period_ID (PK)
Period_Desc eg Jan,Feb etc
Period_Start eg 01/01/02 02/01 etc
Period_End eg 01/31/02 02/28 etc
and we wish to be able to:
1. select individual month say Jan from table
2. Wish to define a collection of months let us say
FirstQuarter to select Jan,Feb,Mar
How do we go about it ? I tried to use two tables
Periods:
Periods_ID (PK)
Periods_Desc eg FirstQuarter
Period:
Period_ID (PK)
Periods_ID (FK)
Period_Desc eg Jan,Feb etc
Period_Start eg 01/01/02 02/01 etc
Period_End eg 01/31/02 02/28 etc
then I could populate the Period table with the Periods_ID
and the following would allow me to select FirstQuarter as follows:
SQL> select periods_desc,period_desc,period_start,period_end from
period,periods
where periods.periods_id = period.periods_id;
PERIODS_DESC PERIOD_DESC PERIOD_START PERIOD_END
=============== =============== ============ ===========
4TH Quarter DEC 2002-12-01 2002-12-31
4TH Quarter NOV 2002-11-01 2002-11-30
4TH Quarter OCT 2002-10-01 2002-10-31
============================================================================
====
SQL> select period_desc,period_start,period_end from period where
period.periods
_id = 7;
PERIOD_DESC PERIOD_START PERIOD_END
=============== ============ ===========
DEC 2002-12-01 2002-12-31
NOV 2002-11-01 2002-11-30
OCT 2002-10-01 2002-10-31
============================================================================
====
SQL> select * from period;
PERIOD_ID PERIODS_ID PERIOD_DESC PERIOD_START PERIOD_END
============ ============ =============== ============ ===========
1 7 DEC 2002-12-01 2002-12-31
2 7 NOV 2002-11-01 2002-11-30
3 7 OCT 2002-10-01 2002-10-31
4 <null> SEP 2002-09-01 2002-09-30
5 <null> AUG 2002-08-01 2002-08-31
6 <null> JUL 2002-07-01 2002-07-31
============================================================================
====
SQL> select * from periods;
PERIODS_ID PERIODS_DESC
============ ===============
7 4TH Quarter
What you want in an application is to have access to both the Periods and
the
Period table, that is you want to have a single period sometimes and other
times
to have access to a period that is made up of other periods. How is one
suppose
to do this in the RDBMS world ??
George R Smith