select 产品名称 , sum(费用A) 费用A, sum(费用B) 费用B,sum(费用C) 费用C,sum(费用D) 费用D
from
(
select * from tb_Income
union all
select 产品名称 , -费用A ,- 费用B,- 费用C , -[费用D] from tb_InExpend
) t
group by 产品名称
from
(
select * from tb_Income
union all
select 产品名称 , -费用A ,- 费用B,- 费用C , -[费用D] from tb_InExpend
) t
group by 产品名称
select 产品名称 , sum(费用A) 费用A, sum(费用B) 费用B,sum(费用C) 费用C,sum(费用D) 费用D
from
(
select * from tb_Income
union all
select 产品名称 , -费用A ,- 费用B,- 费用C , -[费用D] from tb_InExpend
) t
group by 产品名称--插入临时表
select 产品名称 , sum(费用A) 费用A, sum(费用B) 费用B,sum(费用C) 费用C,sum(费用D) 费用D
into 临时表
from
(
select * from tb_Income
union all
select 产品名称 , -费用A ,- 费用B,- 费用C , -[费用D] from tb_InExpend
) t
group by 产品名称
select a.产品名称,a.费用A-b.费用A 费用A,a.费用b-b.费用b 费用b,a.费用c-b.费用c 费用c,a.费用d-b.费用d 费用d into #temp from tb_Income a,tb_InExpend d where a.产品名称=b.产品名称
into #temp
from tb_Income A,tb_InExpend B
where A.产品名称=B.产品名称
select
a.产品名称,
sum(a.费用A-b.费用A) as 费用A,
sum(a.费用B-b.费用B) as 费用B,
sum(a.费用C-b.费用C) as 费用C,
sum(a.费用D-b.费用D) as 费用D
from tb_Income a
left join tb_InExpend b
on a.产品名称=b.产品名称
group by a.产品名称
请教一下:into #temp是不是和 into 临时表 没有区别
into 临时表 --我没有加#,是正式表,即所谓的临时使用的表,用完后删除.