1. 创建子查询临时表,当前会话中可以查询到,创建临时表需要指定表空间,不然会使用默认的表空间。
CREATE TABLE temp_table TABLESPACE tablespace_name AS
SELECT id, number, count(1) AS total
FROM example_table
GROUP BY id, number
having count(1) > 2
ORDER BY id;
临时表temp_table中的字段就是SELECT语句查询出来的id,number,total这三个字段。
2. 查询临时表数据
SELECT * FROM temp_table;
临时表可以与其他表进行关联查询。