嗨,我需要用重复的数据在MySQL表上做一些反错误处理。
我的“出版物”表目前采用这种格式:
Publications Source Table
| title | author
--------------------------------------------
| my paper | michael
| my paper | bill
| my paper | jill
| other paper | tom
| other paper | amy
| third paper | ben
| third paper | sophie我需要将其更改为以下格式:
Publications Destination Table
| title | author | author2 | author 3
|-----------------------------------------------------------------
| my paper | michael | bill | jill
| other paper | tom | amy |
| third paper | ben | sophie |现在,作为您的信息,我需要这样做,这样我最终可以得到一个CSV文件,这样数据就可以从旧系统导出到一个需要这种格式的CSV文件的新系统中。
此外,表中还有许多其他字段,源表中大约有60,000行,但只有大约15,000个唯一的标题。在源表中,每个作者有一行。在目标中,标题将是唯一的标识符。我需要每一个唯一的出版物标题一行。此外,如果这使得问题变得更容易的话,我也可以预先计算出任何一个出版物上的作者人数最多。
我如何在MySQL中做到这一点?谢谢
发布于 2016-11-15 17:11:16
我的建议是实际上将表规范化,而不是为补充作者添加新列。因此,您的新表结构应该如下所示:
Publications Source Table
| title_id | title
--------------------------------------------
| 1 | my paper
| 2 | other paper
| 3 | third paper
| title_id | author
--------------------------------------------
| 1 | michael
| 1 | bill
| 1 | jill
| 2 | tom
| 2 | amy
| 3 | ben
| 3 | sophiehttps://stackoverflow.com/questions/40615679
复制相似问题