以下の画像をご覧ください。それは基本的に私のデータベースがどのように見えるかです。
BI_EMPLOYEE テーブルには、今日の現在のレコードが常に含まれています。ただし、以前の日付から有効になる場合があります。
たとえば、画像に示されている従業員 Anna は 3 月 31 日から入社し、今日までその従業員に更新はありません。
したがって、BI_EMPLOYEE の発効日は 2012 年 3 月 31 日です。
しかし、後で、現在わかっている将来の日付で従業員への動きがあるかもしれません.
たとえば、アンナは 5 月 10 日にアジアから私たちに引っ越します。そのため、5 月 10 日から有効な彼女の地域は私たちになります。
したがって、すべての従業員のリストと、有効日ごとのステータスを示すレポートが必要です。基本的に、すべての従業員はさまざまな日付ですべての活動と更新を行います。
また、すべての更新とアクティビティを実行するスケジュールを毎日実行します。つまり、更新とアクティビティ テーブルから BI_EMPLOYEE TABLE に変更を加えます。
そのため、5 月 10 日に schedular は地域を asia から us に変更します。
また、予想される結果を伴う画像をアタッチしました。
Oracleデータベースを使用しています。
助けてください。
基本的に、必要な出力を提供するビューを作成する必要があります。これにより、任意のレポートに対していつでもクエリを実行できます。
編集1:
以下はDDLとDMLです
--------------------------------------------------------
-- DDL for Table BI_REGION
--------------------------------------------------------
CREATE TABLE "BI_REGION"
( "REGION_ID" NUMBER(*,0) NOT NULL ENABLE,
"REGION_NAME" VARCHAR2(4000) NOT NULL ENABLE
) ;
--------------------------------------------------------
-- DATA FOR TABLE BI_REGION
--------------------------------------------------------
Insert into BI_REGION (REGION_ID,REGION_NAME) values (1,'Asia');
Insert into BI_REGION (REGION_ID,REGION_NAME) values (2,'US');
Insert into BI_REGION (REGION_ID,REGION_NAME) values (3,'UK');
Insert into BI_REGION (REGION_ID,REGION_NAME) values (4,'Germany');
Insert into BI_REGION (REGION_ID,REGION_NAME) values (5,'EUROPE');
Insert into BI_REGION (REGION_ID,REGION_NAME) values (6,'AUSTRALIA');
-------------------------------------------------------
-- DDL for Table BI_COUNTRY
--------------------------------------------------------
CREATE TABLE "BI_COUNTRY"
( "COUNTRY_ID" NUMBER(*,0) NOT NULL ENABLE,
"COUNTRY_NAME" VARCHAR2(4000) NOT NULL ENABLE
) ;
-- DATA FOR TABLE BI_COUNTRY
-- FILTER = none used
---------------------------------------------------
REM INSERTING into BI_COUNTRY
Insert into BI_COUNTRY (COUNTRY_ID,COUNTRY_NAME) values (1,'India');
Insert into BI_COUNTRY (COUNTRY_ID,COUNTRY_NAME) values (2,'USA');
Insert into BI_COUNTRY (COUNTRY_ID,COUNTRY_NAME) values (3,'England');
Insert into BI_COUNTRY (COUNTRY_ID,COUNTRY_NAME) values (4,'Germany');
Insert into BI_COUNTRY (COUNTRY_ID,COUNTRY_NAME) values (5,'New Zealnd');
--------------------------------------------------------
-- DDL for Table BI_DIVISION
--------------------------------------------------------
CREATE TABLE "BI_DIVISION"
( "DIVISION_ID" NUMBER(*,0) NOT NULL ENABLE,
"DIVISION_NAME" VARCHAR2(4000)
) ;
---------------------------------------------------
-- DATA FOR TABLE BI_DIVISION
-- FILTER = none used
---------------------------------------------------
Insert into BI_DIVISION (DIVISION_ID,DIVISION_NAME) values (1,'D1');
Insert into BI_DIVISION (DIVISION_ID,DIVISION_NAME) values (2,'D2');
--------------------------------------------------------
-- DDL for Table BI_PRODUCT
--------------------------------------------------------
CREATE TABLE "BI_PRODUCT"
( "PRODUCT_NAME" VARCHAR2(4000),
"PRODUCT_ID" NUMBER(*,0) NOT NULL ENABLE
) ;
---------------------------------------------------
-- DATA FOR TABLE BI_PRODUCT
-- FILTER = none used
---------------------------------------------------
REM INSERTING into BI_PRODUCT
Insert into BI_PRODUCT (PRODUCT_NAME,PRODUCT_ID) values ('P1','1');
Insert into BI_PRODUCT (PRODUCT_NAME,PRODUCT_ID) values ('P2','2');
--------------------------------------------------------
-- DDL for Table BI_EMPLOYEE_ACTIVITY
--------------------------------------------------------
CREATE TABLE "BI_EMPLOYEE_ACTIVITY"
( "ACTIVITY_ID" NUMBER(*,0) NOT NULL ENABLE,
"STATUS" NUMBER(*,0),
"STATUS_2" NUMBER(*,0),
"STATUS_3" VARCHAR2(4000),
"CONFIDENTIAL" VARCHAR2(1 CHAR) DEFAULT 'N',
"EFFECTIVE_DATE" DATE,
"PARENT_ACTIVITY_ID" NUMBER(*,0),
"EXECUTED" VARCHAR2(1 CHAR) DEFAULT 'N',
"EMPLOYEE_ID" NUMBER
) ;
---------------------------------------------------
-- DATA FOR TABLE BI_EMPLOYEE_ACTIVITY
-- FILTER = none used
---------------------------------------------------
REM INSERTING into BI_EMPLOYEE_ACTIVITY
Insert into BI_EMPLOYEE_ACTIVITY (ACTIVITY_ID,EMPLOYEE_ID, STATUS,STATUS_2,STATUS_3,CONFIDENTIAL,EFFECTIVE_DATE,PARENT_ACTIVITY_ID,)
values (1,1,'Leaver','Intra Region','','No','10-May-2012',0);
Insert into BI_EMPLOYEE_ACTIVITY (ACTIVITY_ID,EMPLOYEE_ID, STATUS,STATUS_2,STATUS_3,CONFIDENTIAL,EFFECTIVE_DATE,PARENT_ACTIVITY_ID,)
values (2,1,'Joiner','Intra Region','','No','10-May-2012',1);
Insert into BI_EMPLOYEE_ACTIVITY (ACTIVITY_ID,EMPLOYEE_ID, STATUS,STATUS_2,STATUS_3,CONFIDENTIAL,EFFECTIVE_DATE,PARENT_ACTIVITY_ID,)
values (3,1,'Leaver','Intra Region','','No','10-June-2012',0);
Insert into BI_EMPLOYEE_ACTIVITY (ACTIVITY_ID,EMPLOYEE_ID, STATUS,STATUS_2,STATUS_3,CONFIDENTIAL,EFFECTIVE_DATE,PARENT_ACTIVITY_ID,)
values (4,1, 'Joiner','Intra Region','','No','10-June-2012',3);
Insert into BI_EMPLOYEE_ACTIVITY (ACTIVITY_ID,EMPLOYEE_ID, STATUS,STATUS_2,STATUS_3,CONFIDENTIAL,EFFECTIVE_DATE,PARENT_ACTIVITY_ID,)
values (5,1,'Leaver','Intra Region','','No','10-July-2012',0);
Insert into BI_EMPLOYEE_ACTIVITY (ACTIVITY_ID,EMPLOYEE_ID, STATUS,STATUS_2,STATUS_3,CONFIDENTIAL,EFFECTIVE_DATE,PARENT_ACTIVITY_ID,)
values (6,1, 'Joiner','Intra Region','','No','10-July-2012',5);
Insert into BI_EMPLOYEE_ACTIVITY (ACTIVITY_ID,EMPLOYEE_ID, STATUS,STATUS_2,STATUS_3,CONFIDENTIAL,EFFECTIVE_DATE,PARENT_ACTIVITY_ID,)
values (7,1,'Leaver','Intra Business','','No','10-Aug-2012',0);
Insert into BI_EMPLOYEE_ACTIVITY (ACTIVITY_ID,EMPLOYEE_ID, STATUS,STATUS_2,STATUS_3,CONFIDENTIAL,EFFECTIVE_DATE,PARENT_ACTIVITY_ID,)
values (8,1, 'Joiner','Intra Business','','No','10-Aug-2012',7);
Insert into BI_EMPLOYEE_ACTIVITY (ACTIVITY_ID,EMPLOYEE_ID, STATUS,STATUS_2,STATUS_3,CONFIDENTIAL,EFFECTIVE_DATE,PARENT_ACTIVITY_ID,)
values (9,1,'Leaver','Intra Business','','No','10-Sep-2012',0);
Insert into BI_EMPLOYEE_ACTIVITY (ACTIVITY_ID,EMPLOYEE_ID, STATUS,STATUS_2,STATUS_3,CONFIDENTIAL,EFFECTIVE_DATE,PARENT_ACTIVITY_ID,)
values (10,1, 'Joiner','Intra Business','','No','10-Sep-2012',9);
--------------------------------------------------------
-- DDL for Table BI_EMPLOYEE
--------------------------------------------------------
CREATE TABLE "BI_EMPLOYEE"
( "EMP_ID" NUMBER(*,0) NOT NULL ENABLE,
"FIRSTNAME" VARCHAR2(4000),
"LASTNAME" VARCHAR2(4000),
"DIVISION_ID" NUMBER(*,0),
"PRODUCT_ID" NUMBER(*,0),
"REGION_ID" NUMBER(*,0),
"COUNTRY_ID" NUMBER(*,0),
"CITY" VARCHAR2(4000) ,
"EFFECTIVE_DATE" DATE
) ;
---------------------------------------------------
-- DATA FOR TABLE BI_EMPLOYEE
-- FILTER = none used
---------------------------------------------------
Insert into BI_EMPLOYEE (EMP_ID,FIRSTNAME,LASTNAME,DIVISION_ID,PRODUCT_ID,REGION_ID,COUNTRY_ID,EFFECTIVE_DATE,CITY) values (1,'Ana','Johnston',1,1,1,1,'31-March-2012','Mumbai');
--------------------------------------------------------
-- DDL for Table BI_EMPLOYEE_UPDATE
--------------------------------------------------------
CREATE TABLE "BI_EMPLOYEE_UPDATE"
( "EMPLOYEE_UPDATE_ID" NUMBER(*,0) NOT NULL ENABLE,
"EMPLOYEE_ID" NUMBER(*,0),
"COLUMN_NAME" VARCHAR2(4000),
"OLD_VALUE" VARCHAR2(4000),
"NEW_VALUE" VARCHAR2(4000),
"EFFECTIVE_DATE" DATE,
"EXECUTED" VARCHAR2(1 CHAR) DEFAULT 'N',
"ACTIVITY_ID" NUMBER
) ;
---------------------------------------------------
-- DATA FOR TABLE BI_EMPLOYEE_UPDATE
-- FILTER = none used
---------------------------------------------------
Insert into BI_EMPLOYEE_UPDATE (EMPLOYEE_ID,COLUMN_NAME,OLD_VALUE,NEW_VALUE,EFFECTIVE_DATE,EXECUTED,ACTIVITY_ID) values (1,'REGION_ID','1','2','10-May-2012', 'N', 1);
Insert into BI_EMPLOYEE_UPDATE (EMPLOYEE_ID,COLUMN_NAME,OLD_VALUE,NEW_VALUE,EFFECTIVE_DATE,EXECUTED,ACTIVITY_ID) values (1,'COUNTRY_ID','1','2','10-May-2012', 'N', 1);
Insert into BI_EMPLOYEE_UPDATE (EMPLOYEE_ID,COLUMN_NAME,OLD_VALUE,NEW_VALUE,EFFECTIVE_DATE,EXECUTED,ACTIVITY_ID) values (1,'CITY','Mumbai','New York','10-May-2012', 'N', 1);
Insert into BI_EMPLOYEE_UPDATE (EMPLOYEE_ID,COLUMN_NAME,OLD_VALUE,NEW_VALUE,EFFECTIVE_DATE,EXECUTED,ACTIVITY_ID) values (1,'REGION_ID','2','3','10-June-2012', 'N', 3);
Insert into BI_EMPLOYEE_UPDATE (EMPLOYEE_ID,COLUMN_NAME,OLD_VALUE,NEW_VALUE,EFFECTIVE_DATE,EXECUTED,ACTIVITY_ID) values (1,'COUNTRY_ID','2','3','10-June-2012', 'N', 3);
Insert into BI_EMPLOYEE_UPDATE (EMPLOYEE_ID,COLUMN_NAME,OLD_VALUE,NEW_VALUE,EFFECTIVE_DATE,EXECUTED,ACTIVITY_ID) values (1,'CITY','New York','London','10-June-2012', 'N', 3);
Insert into BI_EMPLOYEE_UPDATE (EMPLOYEE_ID,COLUMN_NAME,OLD_VALUE,NEW_VALUE,EFFECTIVE_DATE,EXECUTED,ACTIVITY_ID) values (1,'REGION_ID','3','4','10-July-2012', 'N', 5);
Insert into BI_EMPLOYEE_UPDATE (EMPLOYEE_ID,COLUMN_NAME,OLD_VALUE,NEW_VALUE,EFFECTIVE_DATE,EXECUTED,ACTIVITY_ID) values (1,'COUNTRY_ID','3','4','10-July-2012', 'N', 5);
Insert into BI_EMPLOYEE_UPDATE (EMPLOYEE_ID,COLUMN_NAME,OLD_VALUE,NEW_VALUE,EFFECTIVE_DATE,EXECUTED,ACTIVITY_ID) values (1,'CITY','London','frankfurt','10-July-2012', 'N', 5);
Insert into BI_EMPLOYEE_UPDATE (EMPLOYEE_ID,COLUMN_NAME,OLD_VALUE,NEW_VALUE,EFFECTIVE_DATE,EXECUTED,ACTIVITY_ID) values (1,'DIVISION_ID','1','2','10-Aug-2012', 'N', 7);
Insert into BI_EMPLOYEE_UPDATE (EMPLOYEE_ID,COLUMN_NAME,OLD_VALUE,NEW_VALUE,EFFECTIVE_DATE,EXECUTED,ACTIVITY_ID) values (1,'Product_ID','1','2','10-Aug-2012', 'N', 7);
Insert into BI_EMPLOYEE_UPDATE (EMPLOYEE_ID,COLUMN_NAME,OLD_VALUE,NEW_VALUE,EFFECTIVE_DATE,EXECUTED,ACTIVITY_ID) values (1,'PRODUCT_ID','2','3','10-Sep-2012', 'N', 9);
Insert into BI_EMPLOYEE_UPDATE (EMPLOYEE_ID,COLUMN_NAME,OLD_VALUE,NEW_VALUE,EFFECTIVE_DATE,EXECUTED,ACTIVITY_ID) values (1,'LASTNAME','Johnston','thomas','10-Nov-2012', 'N', 0);
わかった