插入临时 table mysql

Insert into temporary table mysql

select t.* 
into #temp 
from 
( 
select 'a' as a 
union all 
select 'b' as a 
) as t 

select * from #temp 

drop table #temp 

我通常在 SQL 服务器上执行此操作,其中我创建了一个临时 table。 语法 "into #temp" 在数据库上创建一个非物理的 table,而 "into temp" 将在数据库上创建一个物理的 table。

我在MySQL的问题是转换上面的MSSQL语句。我想要创建的是一个临时的 table,它不是在数据库上实际创建的。我们在 MySQL 中有此功能吗?

在 MySQL 中,您将使用 create temporary table as:

create temporary table temp as
    select 'a' as a 
    union all 
    select 'b' as a ;