如何从一个表中的数据插入到另一个表中的相同字段 有两个表都有item_type字段 其他的字段有些相同 有些不同由于要对应插入的字段实在是太多 不想一个一个对照着写下去 请问各位大侠有什么好的解决方法 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 一般插入记录则可以insert into table2 select * from table1;更新则update table1 inner join talbe2 on table1.col=table2.colset table1.coln=talbe2.coln 没有办法,只有一个一个地写inser into tt(f1,f2,f3) select f2,f3,f1 from tt1 如果是这样 insert into table1 (col1,col2,...coln) from select col1,col2,...coln from table1;则没什么好办法。一般是直接先把所有列DESC出来,然后贴到EXCEL中,再字处理一下。 mysql> select * from text;+----+-------+------------+| id | value | articles |+----+-------+------------+| 1 | aaa | 1-2,4-9,37 || 2 | bbb | 23,80 || 3 | ccc | 1-24 |+----+-------+------------+3 rows in set (0.00 sec)mysql> select * from test;+----+-------+---------+-----+| id | class | name | age |+----+-------+---------+-----+| 1 | A | aaa | 20 || 2 | A | bbb | 25 || 3 | B | ddd | 30 || 4 | C | sss | 40 || 5 | B | sssffff | 50 || 6 | A | rrr | 33 || 7 | A | eee | 15 || 8 | B | www | 55 || 9 | C | hhh | 22 |+----+-------+---------+-----+9 rows in set (0.00 sec)mysql> insert into test select null,value,articles,10 from text;Query OK, 3 rows affected (0.02 sec)Records: 3 Duplicates: 0 Warnings: 0mysql> select * from test;+----+-------+------------+-----+| id | class | name | age |+----+-------+------------+-----+| 1 | A | aaa | 20 || 2 | A | bbb | 25 || 3 | B | ddd | 30 || 4 | C | sss | 40 || 5 | B | sssffff | 50 || 6 | A | rrr | 33 || 7 | A | eee | 15 || 8 | B | www | 55 || 9 | C | hhh | 22 || 10 | aaa | 1-2,4-9,37 | 10 || 11 | bbb | 23,80 | 10 || 12 | ccc | 1-24 | 10 |+----+-------+------------+-----+12 rows in set (0.00 sec)mysql> update test set age=15 where id=10;Query OK, 1 row affected (0.03 sec)Rows matched: 1 Changed: 1 Warnings: 0其中10这个constant就是两表之间不同值的列 要你自己进行update的 弱弱的问一下 SQL是什么,MySQL又是什么 列举不满足第一范式的例子 请教排序问题,谢谢 JDBC连接MySql数据库的版本问题? 关于POSTSQL的回滚问题 请教:如何将查询结果从纵向变成横向? 如何在Windows上安装两个Mysql服务 求一个执行语句前等待的命令 通过asp表单提交中文数据到mysql数据库中,怎么都是???? 求指导:一条SQL语句的调优问题 请教一种在MySQL中的对数据的统计方法 如何在执行insert语句后触发器触发其他程序
set table1.coln=talbe2.coln
inser into tt(f1,f2,f3) select f2,f3,f1 from tt1
则没什么好办法。一般是直接先把所有列DESC出来,然后贴到EXCEL中,再字处理一下。
+----+-------+------------+
| id | value | articles |
+----+-------+------------+
| 1 | aaa | 1-2,4-9,37 |
| 2 | bbb | 23,80 |
| 3 | ccc | 1-24 |
+----+-------+------------+
3 rows in set (0.00 sec)mysql> select * from test;
+----+-------+---------+-----+
| id | class | name | age |
+----+-------+---------+-----+
| 1 | A | aaa | 20 |
| 2 | A | bbb | 25 |
| 3 | B | ddd | 30 |
| 4 | C | sss | 40 |
| 5 | B | sssffff | 50 |
| 6 | A | rrr | 33 |
| 7 | A | eee | 15 |
| 8 | B | www | 55 |
| 9 | C | hhh | 22 |
+----+-------+---------+-----+
9 rows in set (0.00 sec)mysql> insert into test select null,value,articles,10 from text;
Query OK, 3 rows affected (0.02 sec)
Records: 3 Duplicates: 0 Warnings: 0mysql> select * from test;
+----+-------+------------+-----+
| id | class | name | age |
+----+-------+------------+-----+
| 1 | A | aaa | 20 |
| 2 | A | bbb | 25 |
| 3 | B | ddd | 30 |
| 4 | C | sss | 40 |
| 5 | B | sssffff | 50 |
| 6 | A | rrr | 33 |
| 7 | A | eee | 15 |
| 8 | B | www | 55 |
| 9 | C | hhh | 22 |
| 10 | aaa | 1-2,4-9,37 | 10 |
| 11 | bbb | 23,80 | 10 |
| 12 | ccc | 1-24 | 10 |
+----+-------+------------+-----+
12 rows in set (0.00 sec)
mysql> update test set age=15 where id=10;
Query OK, 1 row affected (0.03 sec)
Rows matched: 1 Changed: 1 Warnings: 0其中10这个constant就是两表之间不同值的列 要你自己进行update的