日期:2014-05-18 浏览次数:20615 次
declare @manager table (manager_id int,Manager_Name varchar(20))
declare @Actual table (Manager_Name varchar(20),Num_of_Deal int,Assets int,Sales_year numeric(28,2),Revs numeric(28,2),[Year] int)
declare @Projected table (Manager_Name varchar(20),Num_of_Deal int,Assets int,Sales_year numeric(28,2),Revs numeric(28,2),[Year] int)
insert @manager select
1, 'ACA'
union all select
2, 'AL'
union all select
3, 'ttt'
union all select
4, 'fff'
insert @Actual select
'ACA', 1 , 200 , 63379.00 , 11995.44 , 2007
union all select
'AL' , 1 , 300 , 60010.00 , 6160.68 , 2007
---------------
insert @Projected select
'ACA', 1, 333, 66700.00 , 1377.26, 2007
union all select
'ACA', 1 , 333 , 66700.00 , 5550.00 , 2008
---------------
select
a.Manager_Name as Manager,
isnull(c.Num_of_Deal,0) as num_Proj,
isnull(c.Assets,0) as Assets_Proj,
isnull(c.Sales_year,0) as Sales_year_Proj,
isnull(c.Revs,0) as Rev_Proj,
isnull(b.Num_of_Deal,0) as num_Actual,
isnull(b.Assets,0) as Assets_Actual,
isnull(b.Sales_year,0) as Sales_year_Actual,
isnull(b.Revs,0) as Rev_Actual,
isnull(b.Revs,0)+isnull(c.Revs,0) as Total_Rev,
2007 as [Year]
from @manager a
left join @Actual b
on a.Manager_Name=b.Manager_Name and b.[Year]=2007
left join @Projected c
on a.Manager_Name=c.Manager_Name and c.[Year]=2007
--结果一样,略
create table manager(manager_id int,Manager_Name varchar(20))
create table Actual(Manager_Name varchar(20),Num_of_Deal int,Assets int,Sales_year numeric(28,2),Revs numeric(28,2),[Year] int)
create table Projected(Manager_Name varchar(20),Num_of_Deal int,Assets int,Sales_year numeric(28,2)