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语句如下:
(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;
相关文章推荐
- Redis(7)Creating and Using Cluster Mode
- sqlite3 journal
- ORACLE RMAN下针对带库设备的操作
- Oracle 学习之 SQL(二) Restricting and Sorting Data
- mysql实现ORACLE的connect by prior父子递归查询
- redis cluster 集群重启关闭
- oracle net configuration assistant 相关概念汇总
- 创建mysql数据库并指定编码
- 删除数据库mysql
- oracle表空间相关SQL语句
- nodejs+express+mongodb安装
- C# Entity Framework MySql CodeFirst
- hibernate *.hbm.xml 与 hibernate.cfg.xml基本模板(mysql)
- memcache实例:缓存一条sql语句的执行结果
- sql server中查询结果集顺序问题
- MySql in子句 效率低下优化
- sql反模式读书笔记
- PostgreSQL与MySQL常用命令比较[转]
- postgresql命令行[转]
- Mysql的主从同步设置