日期:2014-05-18 浏览次数:20602 次
--> 测试数据:[month]
if object_id('[month]') is not null drop table [month]
create table [month]([year] int,[month] int,[value] numeric(2,1))
insert [month]
select 2011,1,-1.2 union all
select 2011,2,-1.2 union all
select 2011,3,-0.9 union all
select 2011,4,-0.9 union all
select 2011,5,-0.7 union all
select 2011,6,-0.8 union all
select 2011,7,-1.1 union all
select 2011,8,-1.0 union all
select 2011,9,-1.0 union all
select 2011,10,-0.8 union all
select 2011,11,-0.3 union all
select 2011,12,-0.2
--> 测试数据:[day]
if object_id('[day]') is not null drop table [day]
create table [day]([year] int,[month] int,[value] int,[C4] numeric(2,1))
insert [day]
select 2011,1,1,-0.7 union all
select 2011,1,2,-0.2 union all
select 2011,1,3,-0.8 union all
select 2011,1,4,-0.5 union all
select 2011,1,5,-1.2 union all
select 2011,1,6,-1.3 union all
select 2011,1,7,-1.4 union all
select 2011,1,8,-0.8 union all
select 2011,1,9,-1.2 union all
select 2011,1,10,-2.1 union all
select 2011,1,11,-1.4 union all
select 2011,1,12,-1.2 union all
select 2011,1,13,-1.6
select a.[year],a.[month],a.value as [day],a.C4-a.valueb as daymonth
from (
select a.*,b.value as valueb from [day] a inner join [month] b
on a.[year]=b.[year] and a.[month]=b.[month]) a
/*
year month day daymonth
2011 1 1 0.5
2011 1 2 1.0
2011 1 3 0.4
2011 1 4 0.7
2011 1 5 0.0
2011 1 6 -0.1
2011 1 7 -0.2
2011 1 8 0.4
2011 1 9 0.0
2011 1 10 -0.9
2011 1 11 -0.2
2011 1 12 0.0
2011 1 13 -0.4
*/