在mysql中创建临时表

时间:2016-07-02 12:20:41

标签: java mysql

大家是否可以在mysql中使用临时表内的临时表? 就像我使用时一样

CREATE TEMPORARY TABLE bo_attribute_description_group_temp (
    SELECT id 
    FROM bo_attribute_description_group
    WHERE display_name IN ('backoffice.attr.group.services', 'backoffice.attr.group.eyecatchergroup')
);

select * from bo_attribute_description_group_temp;

CREATE TEMPORARY TABLE bo_attribute_description_temp (
    SELECT id
    FROM bo_attribute_description
    WHERE group_id IN (bo_attribute_description_group_temp)
);

但它给了我

Error Code: 1054. Unknown column 'bo_attribute_description_group_temp' in 'where clause'    0.000 sec

为什么???

1 个答案:

答案 0 :(得分:0)

是的,你可以。您必须在第二个create table子查询中使用select子句:

CREATE TEMPORARY TABLE bo_attribute_description_group_temp (SELECT id
                                                        FROM bo_attribute_description_group
                                                        WHERE display_name IN ('backoffice.attr.group.services', 'backoffice.attr.group.eyecatchergroup'));

select * from bo_attribute_description_group_temp;

CREATE TEMPORARY TABLE bo_attribute_description_temp (SELECT id
                                                  FROM bo_attribute_description
                                                  WHERE group_id IN (select id from bo_attribute_description_group_temp));