MySQL 将数据从临时表加载到其他表的过程。流程中需要拆分多值字段
我正在尝试将数据从多值数据库 (Unidata) 导出到 MySQL。假设我的源数据是一个人的 ID 号、名字以及他们居住过的所有州。 states 字段是一个多值字段,我将其导出,以便该字段中的不同值由〜。示例摘录如下所示:
"1234","Sally","NY~NJ~CT"
"1235","Dave","ME~MA~FL"
"3245","Fred","UT~CA"
"2344","Sue","OR"
我已将此数据加载到临时表中
Table:staging
Column 1: personId
Column 2: name
Column 3: states
我想要做的是使用过程将这些数据分成两个表:人员表和状态表。一个人可以在 states 表中拥有许多条目:
Table 1: persons
Column 1: id
Column 2: name
Table 2: states
Column 1: personId
Column 2: state
我的过程从临时表中获取数据并将其转储到表 1 中。但是,我有点不知道如何拆分数据并将其发送到表 2。Sally 需要在州表中包含三个条目(NY、NJ、CT),Dave 需要 3 个条目,Fred 需要 2 个条目苏会有 1(或)。关于如何实现这一目标有什么想法吗?
I'm trying to export data from a multivalue database (Unidata) into MySQL. Lets say my source data was a person's ID number, their first name and all the states they've lived in. The states field is a multi value field and I'm exporting them so that the different values within that field are seperated by a ~. A sample extract looks like:
"1234","Sally","NY~NJ~CT"
"1235","Dave","ME~MA~FL"
"3245","Fred","UT~CA"
"2344","Sue","OR"
I've loaded this data into a staging table
Table:staging
Column 1: personId
Column 2: name
Column 3: states
What I want to do is split this data out into two tables using a procedure: a persons table and a states table. A person can have many entries in the states table:
Table 1: persons
Column 1: id
Column 2: name
Table 2: states
Column 1: personId
Column 2: state
My procedure takes the data from the staging table and dumps it over to table 1 just fine. However, i'm a little lost how how to split the data up and send it to table 2. Sally would need to have three entries in the states table (NY, NJ, CT), Dave would have 3, Fred would have 2 and Sue would have1 (OR). Any ideas on how to accomplish this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试这样的事情: http://pastie.org/1213943
try something like this : http://pastie.org/1213943