我有一個表稱爲插入MySQL的列記錄到第二個表具有不同的列名
爲了
| id | created | customer_id | ... | ... |
我想與記錄移動創建的列和CUSTOMER_ID等第二表稱爲
order_meta
| id | order_id | meta | value |
使元是「創造」和值從訂單的表
創造價值這是可以做到用MySQL查詢或者我需要爲此創造一個腳本?
我有一個表稱爲插入MySQL的列記錄到第二個表具有不同的列名
爲了
| id | created | customer_id | ... | ... |
我想與記錄移動創建的列和CUSTOMER_ID等第二表稱爲
order_meta
| id | order_id | meta | value |
使元是「創造」和值從訂單的表
創造價值這是可以做到用MySQL查詢或者我需要爲此創造一個腳本?
這是你想要的嗎?
insert into order_meta (order_id, meta, value)
insert id, 'created', created
from orders;
如果你想要更多的非規範化列,你可以這樣做:
insert into order_meta (order_id, meta, value)
insert id, m.meta,
(case meta when 'created' then created
when 'customer_id' then customer_id
end)
from orders o cross join
(select 'created' as meta union all
select 'customer_id' as meta
) m
INSERT INTO order_meta (order_id, meta, value)
SELECT id, 'created', created
FROM order
你想副本創建,CUSTOMER_ID從訂單表order_meta? – Sateesh