我需要一些帮助来根据当前表中的数据在 phpMyAdmin sql 中创建临时表。例如,我有一个名为 Animals
的表,其中有几列,其中一列名为 Animal_Size
,我需要创建一个名为 Small Animals 的临时表
由Animals
表中size
为small 的动物组成。
有人可以指导我最好的方法吗?
我看过一些例子,但其中很多似乎不起作用。
最佳答案
如果您需要将所有小动物选择到新表中,则需要使用以下查询:
CREATE TABLE small_animals SELECT * FROM animals WHERE animal_size = 'small'
如果您需要真正的临时表,那么只需将 TEMPORARY 添加到查询中即可:
CREATE TEMPORARY TABLE small_animals_temp SELECT * FROM animals WHERE animal_size = 'small'
更新:由于phpMyAdmin中的解析器存在问题,请在SELECT
之前添加AS
,即:
CREATE TABLE small_animals AS SELECT * FROM animals WHERE animal_size = 'small'
Note: A TEMPORARY table is visible only to the current connection, and is dropped automatically when the connection is closed.
关于mysql - phpMyAdmin SQL - 临时表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36626505/