我在我的网站上使用 wordpress,并且我有大量数据要通过 SQL 导出。问题是我为每个帖子(项目)收到了几行,其中包含类别列下的数据。我想要做的是合并所有类别,所以最终我将只有 1 行的每个帖子包含所有类别。
这是目前我的查询:
SELECT post_title, b.object_id, b.term_taxonomy_id, c.term_id, d.name
FROM wp_posts a
JOIN wp_term_relationships b ON a.ID = b.object_id
JOIN wp_term_taxonomy c ON b.term_taxonomy_id = c.term_taxonomy_id
JOIN wp_terms d ON d.term_id = c.term_id
这是我的结果的一个例子:
post_title object_id term_taxonomy_id term_id name
Holcroft Covenant 2 5 5 Action
Holcroft Covenant 2 6 6 Drama
Holcroft Covenant 2 8 8 Thriller
我想要的结果是:Holcroft Covenant 2 5 5 Action,Drama,Thriller
有任何想法吗?