如何在Mysql中将数据合并到临时表中 [英] How to combine data into a temporary table in Mysql

查看:197
本文介绍了如何在Mysql中将数据合并到临时表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个很大的表,叫做paypal_ipn_orders.在此表中,我有2个重要的信息位,分别为item_name行和sort_num行.我想使用某些参数从paypal_ipn_orders中提取记录并将它们放入称为temp_table的临时表中.我知道如何选择记录,如下所示

I have a very large table called paypal_ipn_orders. In this table I have 2 important bits of information a row called item_name and a row called sort_num. I want to use certain parameters to pull out records from paypal_ipn_orders and put them into a temporary table called temp_table. I know how to select the records as follows

SELECT `item_name`, `sort_num` 
FROM `paypal_ipn_orders`
WHERE `packing_slip_printed` = 0
AND LOWER(`payment_status`) = `completed`
AND `address_name` <> ''

该查询选择了我想移动到临时数据库的所有记录,我只是不知道该怎么做.

That query selects all the records I want to move to the temporary database I just don't know how to do that.

推荐答案

使用MySQL的

Use MySQL's Insert Into Select I added generic data types to the columns in the temp table, you'll want to find out what the actual data types are from your table and make them the same.

CREATE TEMPORARY TABLE temp_table (
    item_name varchar(50), 
    sort_num int
);

INSERT INTO temp_table (item_name, sort_num)
SELECT `item_name`, `sort_num` 
FROM `paypal_ipn_orders`
WHERE `packing_slip_printed` = 0
AND LOWER(`payment_status`) = `completed`
AND `address_name` <> ''

这篇关于如何在Mysql中将数据合并到临时表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆