MySQL中将查询的结果生成临时表,列类型与查询的列一致,百度搜索到的没啥用。
直接上SQL:
将结果生成临时表,临时表只存在于当前jdbc连接session
create temporary table temp_tb_name as
(select id,name,update_time from a_table where id<3)
PS:关闭当前jdbc连接session,temp_tb_name临时表会消失(自动删除)
使用java操作存在连接池时,此临时表只存在于某个jdbc连接,因为连接池不会关闭连接。
手动创建临时表:
CREATE TEMPORARY TABLE temp_tb_bame(
product_name VARCHAR(50) NOT NULL,
total_sales DECIMAL(12,2) NOT NULL DEFAULT 0.00,
avg_unit_price DECIMAL(7,2) NOT NULL DEFAULT 0.00,
total_units_sold INT UNSIGNED NOT NULL DEFAULT 0
);
下面这种写法纯属误导:直接创建物理表了emm…