表A数据如下:
建表:
create table A(
lsase_id varchar2(10),
name varchar2(10),
revenue_code varchar2(10),
start_date date,
end_date date,
amount number(10)
)
insert数据:
insert intoRental_Schedule values('T1','abc','rent',2012/03/12,2013/03/11,30000)
insert intoRental_Schedule values('T1','abc','mgt',2012/03/12,2013/03/11,1800)
呈现:
lease_idnamerevenue_code start_date
end_date
amount
T1
abc
rent
2012/03/12
2013/03/11
30000
T1
abc
mgt
2012/03/12
2013/03/11
1800
然后,表B
建表:
create table actual_lease(
lease_idvarchar2(10),
name varchar2910),
month_year varchar2(10),
revenue_code varchar2(10),
start_date date,
end_datedate,
actual number(10))
呈现:
lease_id
name
month_year
revenue_code
start_date
end_date
actual
T1
abc
03/2012
rent
2012/03/12
2012/03/31
19355
T1
abc
03/2012
mgt
2012/03/12
2012/03/31
1161
..
04/2012
..
04/2012
..
..
..
..
T1
abc
03/2013
rent
2013/03/01
2013/03/11
10645
T1
abc
03/2012
mgt
2013/03/01
2013/03/11
639
现在的问题是这样的,B表中的数据是根据insert into B select A这样的命令插入的,
但大家应该可以看到,B表中的month_year是A表中所没有的.因为这里是绑定变量,就是用户输入的.
例如T1中..SQL句子要判断A表中的start/end date, 比如用户输入了03/2012,则insert到表B中的start/end date就应该是2012/03/12和2012/03/31
然后,输入04/2012的话就应该是2012/04/01和2012/04/30,
到最后的时候,用户输入03/2013,则insert到B表中的则是2013/03/01和2013/03/11
我想问下大家,这样的SQL能写出来吗?我想了好半天都没想到什么好方法!求大家指导下!谢谢了.
|