我建了一个临时表,然后向其中插入了记录当我需要在这个临时表上自连接运算的时候,提示can't reopen table:'a'请问错误在哪里啊?以下是我的临时表:CREATE TEMPORARY TABLE test
(
  partition varchar(2) not null,
  ID bigint not null,
  BeginTime datetime not null,
  EndTime datetime not null
) type = HEAP ;报错语句:select *  from test a  inner join  test b
 on a.begintime<b.endtime ;

解决方案 »

  1.   

    使用临时表的诸多限制
    引擎类型只能是:memory(heap)、myisam、merge、innodb
    不支持mysql cluster
    同一个查询语句中只能引用一次! 如 SELECT * FROM TP_TABLE , TP_TABLE AS ALIAS_NAME;  是错误的
    同一个用户存储函数中只能引用一次!
    show tables 不会显示临时表
    不能使用rename重命名临时表。只能使用ALTER TABLE OLD_TP_TABLE_NAME RENAME NEW_TP_TABLE_NAME;
    影响使用replication功能
      

  2.   

    You cannot refer to a TEMPORARY table more than once in the same query
      

  3.   

    那怎么办?
    我的目标是查询出这段时间内是否有时间重叠,不用连接怎么查?
    请高手指教。实际查询代码:select count(*) into result from test a inner join test b
     on a.begintime<b.endtime and a.endtime>b.begintime ;
      

  4.   

    不用临时表,使用一个常规表,用完后自己通过代码 drop table掉。
      

  5.   

    用物理表不行吗?
    CREATE TABLE test
    (
      partition varchar(2) not null,
      ID bigint not null,
      BeginTime datetime not null,
      EndTime datetime not null
    )  ;
      

  6.   

    那就还是用普通表吧。
    CREATE TABLE test
    (
      partition varchar(2) not null,
      ID bigint not null,
      BeginTime datetime not null,
      EndTime datetime not null
    ) type = HEAP ;用完后,自己把表DROP掉。
      

  7.   

    这个问题 回答 是、不是, 可以说都正确,也就是说都不正确。
    这个要看你的具体实际情况,缓冲内存参数的设置,查询语句的内容和执行次序时间。 比如一个语句你今天执行了一下,然后又执行了上万个不同的SQL语句,你再来执行这个语句,90%的情况下,重要重新分析执行。
      

  8.   

    CREATE TABLE test
    (
     partition varchar(2) not null,
     ID bigint not null,
     BeginTime datetime not null,
     EndTime datetime not null
    ) type = HEAP ;并不会创建磁盘上的数据文件。