假设我有这样的命令:
select name, age, haircolor from people where shoesize > 10;
有没有办法可以根据该命令返回的内容创建新表?我想将该命令的输出传递给一个新表。
含义:
mysql> show tables;
+-----------------+
| Tables_in_db1 |
+-----------------+
| people |
+-----------------+
1 rows in set (0.00 sec)
mysql> CREATE TABLE FROM "select name, age, haircolor from people where shoesize > 10;";
..?
mysql> show tables;
+-----------------+
| Tables_in_db1 |
+-----------------+
| people |
| NEW TABLE |
+-----------------+
1 rows in set (0.00 sec)
答案 0 :(得分:3)
是的,CREATE TABLE语法最后支持SELECT语句,它可以这么简单:
CREATE TABLE foo
SELECT bar FROM xyz;
答案 1 :(得分:2)
您可以使用MySQL's create table...select syntax:
您可以从另一个表创建一个表 通过在。处添加SELECT语句 CREATE TABLE语句的结尾:
CREATE TABLE new_tbl SELECT * FROM orig_tbl;
答案 2 :(得分:1)
答案 3 :(得分:0)