我在phpmyadmin中有3个数据库,在将数据从一个数据库迁移到另一个数据库时需要一些帮助。
表:
CREATE TABLE ethernet.data(
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
event TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
Count0 VARCHAR(10) NOT NULL,
Count1 VARCHAR(10) NOT NULL,
Count2 VARCHAR(10) NOT NULL,
FPY VARCHAR(10) NOT NULL,
)表:
CREATE TABLE ethernet1.data1(
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
event TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
Count0 VARCHAR(10) NOT NULL,
Count1 VARCHAR(10) NOT NULL,
Count2 VARCHAR(10) NOT NULL,
FPY VARCHAR(10) NOT NULL,
)表:
CREATE TABLE fpydcih.data2(
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
event TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
FPYSVSL VARCHAR(10) NOT NULL,
FPYZ2FS VARCHAR(10) NOT NULL,
)ideea将从ethernet.data FPY列导出最后10个值,从ethernet1.data1 FPY列导出最后10个值,并在fpydcih.data2表中导出它们。
发布于 2020-07-24 09:16:59
这只是为了展示这个想法,我还没有检查它,因为我不想创建3个模式。
SET @id1 = 0;
SET @id2 = 0;
INSERT INTO fpydcih.data2 (FPYSVSL, FPYZ2FS)
SELECT
t1.FPY FPYSVSL, t2.FPY FPYZ2FS
FROM
(
SELECT @id1 = @id1 + 1 id, FPY
FROM ethernet.data
ORDER BY id DESC
LIMIT 10
) t1
LEFT JOIN
(
SELECT @id2 = @id2 + 1 id, FPY
FROM fpydcih.data2
ORDER BY id DESC
LIMIT 10
) t2 ON t2.id = t1.id
;发布于 2020-07-24 11:43:11
你似乎想要union all。就像这样:
insert into fpydcih.data2 (id, event, count0, count1, count2, count3, fpa)
(select id, event, count0, count1, count2, count3, fpa
from ethernet.data
order by event desc
limit 10
) union all
(select id, event, count0, count1, count2, count3, fpa
from ethernet1.data1
order by event desc
limit 10
);您也可以将其表述为两个单独的insert,或者如果目标表不存在,则使用create table as。
https://stackoverflow.com/questions/63069712
复制相似问题