将关联表展平为多值列? [英] Flatten association table to multi-value column?
本文介绍了将关联表展平为多值列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个表格,其中只有产品 ID 和类别 ID(产品可以属于多个类别).我怎样才能将类别 ID 拼合到一个产品列中,所以我以这个结束:
I have a table with just product ID's and category ID's (products can be in more than one category). How can I flatten the category ID's into a product column so I end us with this:
id | name | desc | categories
1 | test1 | lorem | 1,3,4,23
2 | test2 | ipsom | 4,6,24
这就像我需要循环到类别列的单独表中.我该怎么做,或者有更好的方法吗?
It is like I need to loop into a separate table for the categories column. How can I do this or is there a better way?
推荐答案
在 MSSQL 中没有内置的方法来做到这一点.
There's no in-built way to do it in MSSQL.
在 Microsoft SQL Server 2005 中模拟 group_concat MySQL 函数? 很好地描述了如何实施变通方法.
Simulating group_concat MySQL function in Microsoft SQL Server 2005? has a good description of how to go about implementing a workaround.
这篇关于将关联表展平为多值列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文