1、把两张表格的数据抽取出来放到另外一张表格中
(1)pt表
role_id int
pt int
(2)season_score表
role_id int
season_score int
(3)player表
role_id int
pt int
season_score int
count int
(4)把pt表和season_score表的数据移动到player表中,并且把player表的count字段的值设置为1
(5)sql语句如下:
REPLACE INTO `player` (
role_id,
`pt`,
`season_score`,
`count`
) SELECT
tmp.t1,
COALESCE (tmp.t2, 0),
COALESCE (tmp.t3, 0),
1
FROM
(
(
SELECT
p.role_id AS t1,
p.pt AS t2,
s.season_score AS t3
FROM
pt AS p
LEFT JOIN season_score AS s ON p.role_id = s.role_id
)
UNION
(
SELECT
s.role_id AS t1,
p.pt AS t2,
s.season_score AS t3
FROM
season_score AS s
LEFT JOIN pt AS p ON p.role_id = s.role_id
)
) tmp;