Select sum(营业额表.金额)
-(Select Sum(金额) From 费用表 Where 日期 Between @StartDate and @EndDate)
-(Select Sum(金额) From 工资表 Where 日期 Between @StartDate and @EndDate)
-(Select Sum(金额) From 耗材表 Where 日期 Between @StartDate and @EndDate) as 利润
From 营业额表
Where 日期 Between @StartDate and @EndDate
select 项目=isnull(a.项目,isnull(b.项目,c.项目))
,利润=isnull(a.营业额,0)-isnull(b.费用,0)-isnull(c.耗材,0)
from(
select 日期,项目,营业额=sum(金额)
from 营业额表
where 日期 between '2004-06-01' and '2004-06-30'
group by 项目
)a full join(
select 项目,费用=sum(金额)
from 费用表
where 日期 between '2004-06-01' and '2004-06-30'
group by 项目
)b on a.项目=b.项目 full join(
select 项目,耗材=sum(金额)
from 耗材表
where 日期 between '2004-06-01' and '2004-06-30'
group by 项目
)c on a.项目=c.项目