【发布时间】:2012-03-31 16:58:46
【问题描述】:
我需要将我的 mysql 数据库导出到 csv 文件。我将要使用它的地方不能有相关的表,所以我需要将相关的记录连接到一个字段中。这可能吗?例如,假设这个表结构:
Items: id as INT, name as VARCHAR
ItemIdentifiers: id as INT, item_id as INT, identifier_id as INT
Identifiers: id as INT, identifier as VARCHAR
ItemColors: id as INT, item_id as INT, color_id as INT
Colors: id as INT, color as VARCHAR
并假设这些数据:
Items: (1, 'some name')
ItemIdentifiers: (1, 1, 1), (2, 1, 2)
Identifiers: (1, 'ident1'), (2, 'ident2')
ItemColors: (1, 1, 1), (2, 1, 2)
Colors: (1, 'blue'), (2, 'green')
我怎么会得到这个:
'一些名字','ident1 ident2','蓝绿色'
这只是一个基本示例,但我希望这能传达我想要做的事情。
【问题讨论】:
-
为什么没有 2 行:一个用于
ident1,另一个用于ident2? -
因为这会造成大量不必要的重复。我最终可能只有 1 个项目有 20 条记录。
标签: mysql export-to-csv