請看下面的圖片。它基本上是我數據庫的外觀。如何獲取不同生效日期的員工詳細信息?
BI_EMPLOYEE表總是有今天的記錄。雖然它可能在某個以前的日期有效。
例如如圖所示的員工Anna從3月31日加入,直到今天沒有對該員工進行更新。
因此,BI_EMPLOYEE有生效日期= 3月31日2012年
但是,後來可能會有變動對將來的日期的員工現在是知道的。
例如安娜在5月10日從亞洲轉移到我們,等等。所以,從10月開始,她的地區將成爲我們。
因此,我需要一份報告,其中列出了所有員工在每個生效日期的狀態。基本上,所有emplyees所有活動和更新日期。
我們還每天運行一次調度,它會運行所有更新和活動,即從更新和活動表向BI_EMPLOYEE TABLE執行chnages。
因此,截至5月10日,地塊將從亞洲轉向我們。
我也提出了預期結果的圖像。
我們正在使用Oracle數據庫。
請幫助。
我將基本上需要創建一個視圖,這將得到期望的輸出然後可以被查詢任何時間以任何報告。
EDIT 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);
好
爲什麼關閉?我一直在嘗試這個很長一段時間沒有運氣:( – ashishjmeshram
不贊同近距離投票 - 我已經遇到過這樣的需求一次或兩次自己。 –
@Jeffrey肯普。嗨。你能解決它嗎?任何對此有何建議? – ashishjmeshram