【发布时间】:2020-03-27 18:00:45
【问题描述】:
我想从数据库列表中导出带有类别和标签的帖子。我试过这个Wordpress SQL: get post category and tags,但它在我的 MySQL 5.7.27 上不起作用并出现错误
Expression #3 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'wpdev.c.name' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
我的预期结果会是一样的
+---------------+----------+----------------+
| post_id | category | tags |
|---------------+----------+----------------+
| 213 | news | tag1,tag2,tag3 |
+---------------+----------+----------------+
我的声明是:
SELECT p.id, p.post_name, c.name, GROUP_CONCAT(t.name)
FROM wp_posts p JOIN wp_term_relationships cr on (p.id=cr.object_id)
JOIN wp_term_taxonomy ct on (ct.term_taxonomy_id=cr.term_taxonomy_id and ct.taxonomy='category')
JOIN wp_terms c on (ct.term_id=c.term_id)
JOIN wp_term_relationships tr on (p.id=tr.object_id)
JOIN wp_term_taxonomy tt on (tt.term_taxonomy_id=tr.term_taxonomy_id and tt.taxonomy='post_tag')
JOIN wp_terms t on (tt.term_id=t.term_id)
GROUP BY p.id
提前致谢。
【问题讨论】:
-
请在此处包含您的实际 SQL 代码以获得最佳结果。
-
``` SELECT p.id, p.post_name, c.name, GROUP_CONCAT(t.
name) FROM wp_posts p JOIN wp_term_relationships cr on (p.id=cr.@987654327 @) JOIN wp_term_taxonomy ct on (ct.term_taxonomy_id=cr.term_taxonomy_idand ct.taxonomy='category') JOIN wp_terms c on (ct.term_id=c.term_id) JOIN wp_term_relationships tr on (p.id=tr.object_id) 加入 wp_term_taxonomy tt on (tt.term_taxonomy_id=tr.term_taxonomy_id和 tt.taxonomy='post_tag') 加入 wp_terms t on (tt.term_id=t.term_id) 按 p.id 分组 ``` @TimBiegeleisen