方法一:
create table #Tmp --创建临时表#Tmp
(
tar varchar(50), --修改后 的 目标值
res varchar(50), --修改前 的 值
);
insert #Tmp
select '爱尔兰','L7667601' union
select '澳大利亚','L67AU0671' union
select '澳门','7777771'
select * from #Tmp;
drop table #Tmp;
方法二:
if OBJECT_ID('tempdb..#temp') is not null
drop table #temp
select * into #temp from
(
select 7 as 'month',25 as 'salesVolume'
union all
select 7 as 'month',25 as 'salesVolume'
union all
select 8 as 'month',25 as 'salesVolume'
union all
select 8 as 'month',25 as 'salesVolume'
union all
select 8 as 'month',25 as 'salesVolume'
union all
select 9 as 'month',25 as 'salesVolume'
union all
select 9 as 'month',25 as 'salesVolume'
union all
select 9 as 'month',25 as 'salesVolume'
union all
select 9 as 'month',25 as 'salesVolume'
) as A
select * from #temp
本文介绍了两种在SQL中创建和使用临时表的方法。第一种方法展示了如何创建一个包含修改前后值的临时表,并从中查询数据后删除。第二种方法则通过检查临时表是否存在并创建包含月份和销售量的数据临时表。

被折叠的 条评论
为什么被折叠?



