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等等
这样: CREATE TEMPORARY TABLE tmp SELECT title,id,"er" FROM question where title like binary '%劳动%' and title like binary '%工人%' and title like '%民族%' ;
谢谢lvlfforever,,用你的方法的出来的结果如下:id title er 12 test er 15 测试 er 200 dddd er假如我还有一个临时表,也是这几个字段。但这个临时表还是er,,,没有起到作用。。还需要更新临时表,把er得值变一下,有没有不需要更新数据库的办法啊!
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
实际上并不需要临时表的 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 这样会有重复的记录在里面?
字段可以加到临时表里。建好之后,alter your_table
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等等
CREATE TEMPORARY TABLE tmp SELECT title,id,"er"
FROM question where title like binary '%劳动%' and title like binary '%工人%' and title like '%民族%' ;
12 test er
15 测试 er
200 dddd er假如我还有一个临时表,也是这几个字段。但这个临时表还是er,,,没有起到作用。。还需要更新临时表,把er得值变一下,有没有不需要更新数据库的办法啊!
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
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
这样会有重复的记录在里面?