mysql - 怎么把表A中数据分别导入到其他两张表中去?

查看:123
本文介绍了mysql - 怎么把表A中数据分别导入到其他两张表中去?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题


table A:
name    name2
a        hello1
b        hello2
c        hello3
c        hello4
d        hello5
d        hello6

将数据分别保存到两张表中去

table B(id,name都是唯一的):
id    name
1    a
2    b
3    c
4    d

table C:
name2    id
hello1    1
hello2    2
hello3    3
hello4    3
hello5    4
hello6    4

解决方案


insert into b(id,name) 
select  (@i:=@i+1)as i,a.name  from (select DISTINCT name from a)a ,(select @i:=0) as tmp;


insert into c(name2,id)
SELECT a.name2,b.id from a,b where a.name=b.name;

这篇关于mysql - 怎么把表A中数据分别导入到其他两张表中去?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆