您能否帮助修改以下 SQL 查询,以便它可以在 mySQL 中工作?目前,错误消息是表 t1 不存在。我想获得一个包含“post_title”、“name1”、“url1”列的表格。
如果有帮助,则可以在 Wordpress CMS 数据库上测试此查询
SELECT t1.post_title,
(select meta_value from t1 where t1.meta_key='name1_class' limit 1) as name1,
(select meta_value from t1 where t1.meta_key='url1_class' limit 1) as url1
FROM (select pm.post_id as id, pm.meta_key, pm.meta_value, p.post_title, t.slug from wp_2_postmeta pm
inner join wp_2_posts p on pm.post_id = p.id
inner join wp_2_term_relationships tr on tr.object_id = p.id
inner join wp_2_term_taxonomy tt on tr.term_taxonomy_id = tt.term_taxonomy_id
inner join wp_2_terms t on t.term_id = tt.term_id
where post_type='footercolumn' and post_status='publish' and pm.meta_key like '%class') t1
“FROM”子句中 t1 表的子查询生成如下数据集:
'id', 'meta_key', 'meta_value', 'post_title', 'slug'
'18', 'name1_class', 'Our Work', 'Who we are', 'column1'
'18', 'url1_class', '/work.html', 'Who we are', 'column1'
'18', 'name1_class', 'Our Team', 'About', 'column2'
'18', 'url1_class', 'team.html', 'About', 'column2
我希望结果表是:
'title', 'name1', 'url1'
'Who we are', 'Our Work', 'work.html'
'About', 'Our Team', 'team.html'
谢谢