其实不用四个临时表,只要一个临时表,加个标志字段就行。取的时候order by此字段就可以了。

解决方案 »

  1.   

    谢谢lvlfforever(那一年) ,我就是想知道怎么加上标志字段///谢谢
      

  2.   

    加个类型为tinyint(1)的字段,分别用1,2,3,4对应你的四种情况。选出来之后,order by 这个字段。
      

  3.   

    这个tinyint(1)字段是加在临时表里还是加在数据库中存在的表里!如果加到临时表里,我没有想出来怎么加!
      

  4.   

    这四种情况的数据来自哪里?是同一个表?还是不同的表?
    字段可以加到临时表里。建好之后,alter your_table
      

  5.   

    CREATE TEMPORARY TABLE tmp SELECT title,id 
    FROM question where title like binary '%劳动%' and  title like binary '%工人%' and title like '%民族%' ;select title,id from tmp;如像上面的程序,我的tmp临时表中只有两个字段,title和id....而且这两个字段是通过select,question表出来的。。我怎么能再加上一个字段er(标记),然后title,id这两个字段还存在。我希望得出来的结果为:id  title    er
    12    test      1
    15    测试      1
    200    dddd     1等等
      

  6.   

    这样:
    CREATE TEMPORARY TABLE tmp SELECT title,id,"er" 
    FROM question where title like binary '%劳动%' and  title like binary '%工人%' and title like '%民族%' ;
      

  7.   

    谢谢lvlfforever,,用你的方法的出来的结果如下:id  title    er
    12    test   er  
    15    测试   er
    200    dddd  er假如我还有一个临时表,也是这几个字段。但这个临时表还是er,,,没有起到作用。。还需要更新临时表,把er得值变一下,有没有不需要更新数据库的办法啊!
      

  8.   

    CREATE TEMPORARY TABLE tmp SELECT title,id,1 as er FROM 表1 where 条件1;
    insert into tmp SELECT title,id,2 as er FROM 表2 where 条件2;
    insert into tmp SELECT title,id,3 as er FROM 表3 where 条件3;
    ....select * from tmp order by er;实际上并不需要临时表的
    SELECT title,id,1 as er FROM 表1 where 条件1
    union
    SELECT title,id,2 as er FROM 表2 where 条件2
    union
    SELECT title,id,3 as er FROM 表3 where 条件3
    union
    SELECT title,id,4 as er FROM 表4 where 条件4
    order by er
      

  9.   

    实际上并不需要临时表的
    SELECT title,id,1 as er FROM 表1 where 条件1
    union
    SELECT title,id,2 as er FROM 表2 where 条件2
    union
    SELECT title,id,3 as er FROM 表3 where 条件3
    union
    SELECT title,id,4 as er FROM 表4 where 条件4
    order by er
    这样会有重复的记录在里面?