计算机知识分享网

【mysql】mysql根据查询结果创建表

表明必须在当前库中不存在才可以执行
create table tmp_table_david SELECT * FROM `t_users` where username = 'zhangsan' 
上述代码中

tmp_table_david 是为要创建的结果表的表名
* 则为要查找的内容,也可以是多个字段
t_users 则为原始表
增加一列自增的id
create table 表的名字(id int primary key auto_increment) as select * from '另一张表的名字';
常用方法
create table allgame(id int primary key auto_increment) as
select gameId,gameName,gameType,gameIcon,gamePublishAt,gameDesc,gamePlatform,gameTags,gameOfficialPic from singlegame 
union
select gameId,gameName,gameType,gameIcon,gamePublishAt,gameDesc,gamePlatform,gameTags,gameOfficialPic from phonegame 
UNION
SELECT gameId,gameName,gameType,gameIcon,gamePublishAt,gameDesc,gamePlatform,gameTags,gameOfficialPic FROM netgame

#Mysql