鉴于此表:
CREATE TABLE positions
( "EMP_ID" CHAR(10 BYTE),
"GTYPE" NUMBER,
"AMT" NUMBER,
"START_DATE" DATE,
"STOP_DATE" DATE
)
这个数据:
Insert Into positions (Emp_Id,Gtype,Amt,Start_Date,Stop_Date)
select 'XA0022',1,1000,'01-MAY-2010','08-MAY-2012' from dual union
Select 'XA0022',1,1000,'01-MAY-2010','31-DEC-2012' From Dual Union
Select 'XA0022',2,500,'03-APR-2012','15-JUL-2012' From Dual Union
Select 'XA0022',1,421,'01-MAY-2012','23-MAY-2012' From Dual Union
Select 'XA0022',1,1514,'09-MAY-2012','31-DEC-2012' From Dual union
select 'XA0022',1,600,'24-MAY-2012','24-MAY-2012' from dual;
我如何做到这一点:
from to type1 type2
01-May-2010 02-Apr-2012 2000 0
03-Apr-2012 30-Apr-2012 2000 500
01-May-2012 07-May-2012 2421 500
08-May-2012 08-May-2012 2421 500
09-May-2012 22-May-2012 2935 500
23-May-2012 23-May-2012 2935 500
24-May-2012 15-Jul-2012 3114 500
16-Jul-2012 31-Dec-2012 3014 0
注意:金额在 start_date 生效,在 stop_date 之后的第二天无效。
任何指点都感激不尽!