我需要:
加入来自多个表的wordpress数据,以便所有与每个帖子相关的数据都驻留在一行上,以便导出为CSV。
和
在导入CSV期间将数据拆分回表格。
我相信这可以通过2个mySQL查询完成。
我的目的是导出数据,操纵单元格值并添加新行,以便批量编辑和创建新的wp帖子。
到目前为止,我已经明白我可以非常明确地将这些数据整理出来:
SELECT DISTINCT
ID, post_author, post_content, post_title
,(SELECT meta_value
FROM wp_postmeta
WHERE wp_postmeta.meta_key = 'wpcf-album-title'
AND wp_postmeta.post_id = wp_posts.ID
) as "wpcf-album-title"
,(SELECT id FROM wp_geo_mashup_locations, wp_geo_mashup_location_relationships WHERE wp_geo_mashup_locations.id = wp_geo_mashup_location_relationships.location_id AND wp_geo_mashup_location_relationships.object_id = wp_posts.ID) as "id"
FROM wp_posts
WHERE post_type = 'post'
ORDER BY
ID, post_author, post_content, post_title
INTO OUTFILE '/tmp/test.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '~'
LINES TERMINATED BY '\n'
上面给出了一个选择并导出到CSV文件。
如何以相反的方式返回,将数据分成几个表?
答案 0 :(得分:1)
看起来wp_geo_mashup_location_relationships.location_id
是有效表中的有效字段(最后在http://psc.apl.washington.edu/wordpress/wp-content/uploads/_people/PSCAdmin-migrate-5cb4d.sql找到它),所以......
您需要让SQL了解wp_geo_mashup_location_relationships
表,将其包含在FROM
子句中,否则您将收到该错误。
,(SELECT lat
FROM wp_geo_mashup_locations, wp_geo_mashup_location_relationships
WHERE wp_geo_mashup_locations.id = wp_geo_mashup_location_relationships.location_id
AND wp_geo_mashup_location_relationships.object_id = wp_posts.ID
) as "lat"