如何查询2表,结果集赋值给临时表。 承认自己是有点懒了……表1:字段A,字段B表2:字段C,字段D(需要的)临时表:字段E,字段Finsert into #临时表select * from 表1unionselect* from 表2表1的字段A+表2的字段C=临时表的字段E表1的字段B+表2的字段D=临时表的字段F1、不知道怎么对应起来……2、写在存储过程里面时,是否需要声明创建#临时表?或者是直接写? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 不需要临时可以解决,直接写insert into 表名(E,F)select sum(A) as A,sum(B) as bfrom(select A,B from 表1 union select C,D from 表2 )t --不声明select e,f into #tbfrom ( select a as e,b as f from tb1 union all select c,d from tb2) tmp--另外需注意对应字段的数据类型是否可以这样做union all。 --不声明select e,f into #tbfrom ( select a as e,b as f from tb1 union all select c as e,d as f from tb2) tmp--另外需注意对应字段的数据类型是否可以这样做union all。应该是这样? 通过名字查id,有相同名字的怎么返回多个id? 各位高手,小弟求一SQL语句 数据库语句求助:立马结帐 求一SQL~~~~~~ 这是为什么啊,各位大侠!!!!!!! 如何在程序中作到动态的将视图转换成文本存放到固定地方? 求助高手,压缩数据库后,磁盘产生碎片,如何消除? 事务的问题 SQL Server Index的B-Tree定义 一个表的统计结果放到另一个表中去的存储过程怎样写? create view裏面有union all 不能排序 各位大大们,这个问题的语句怎么写啊
insert into 表名(E,F)
select sum(A) as A,sum(B) as b
from(
select A,B from 表1
union select C,D from 表2
)t
--不声明select e,f into #tb
from (
select a as e,b as f from tb1
union all
select c,d from tb2
) tmp--另外需注意对应字段的数据类型是否可以这样做union all。
from (
select a as e,b as f from tb1
union all
select c as e,d as f from tb2
) tmp--另外需注意对应字段的数据类型是否可以这样做union all。应该是这样?