您的位置:首页 > 数据库

SQL语句练习

2015-08-21 23:51 288 查看
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;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: