我正在寻找解决方案:
SELECT ID
, post_date_gmt
, post_content
, post_title
, post_modified_gmt
FROM wphj_posts
WHERE post_status = 'publish'
和
SELECT DISTINCT meta_value
, post_id
, meta_id
FROM wphj_postmeta
WHERE meta_key LIKE '_wp_attached_file'
ORDER
BY meta_value ASC
我首先做的是这个,它不能按照我的要求工作:
SELECT ID
, post_date_gmt
, post_content
, post_title
, post_modified_gmt
, meta_value
FROM wphj_posts
, wphj_postmeta
WHERE post_status = 'publish'
AND meta_key LIKE '_wp_attached_file'
我只是试图查询WordPress数据库以获取wp_posts
的帖子数据和wp_postmeta
表格中相同帖子的精选图片。
我试图做的东西:使用union,unionall,join on,inner join,left join。不幸的是他们不起作用。
更新,使用wpDatatables插件得出这个,在插件仪表板上工作,但不是自己的查询:\ - 我做错了什么人
SELECT posts_post.ID AS post_ID,
posts_post.post_date_gmt AS post_post_date_gmt,
posts_post.post_title AS post_post_title,
CONCAT('<a href="',posts_post.guid,'">',posts_post.post_title,'</a>') AS post_title_with_link_to_post,
posts_post.post_content AS post_post_content,
posts_post.post_status AS post_post_status,
posts_post.post_name AS post_post_name,
CONCAT(
'<a href="',
posts_post.guid,
'"><img src="',
REPLACE(
posts_post_img.guid,
CONCAT(
'.',
SUBSTRING_INDEX(
posts_post_img.guid,
'.',
-1
)
),
CONCAT(
'-150x150.' ,
SUBSTRING_INDEX(
posts_post_img.guid,
'.',
-1
)
)
),
'" /></a>'
) AS post_thumbnail_with_link_to_post,
post_taxonomy_category_tbl.name AS post_taxonomy_category
FROM wphj_posts AS posts_post
INNER JOIN (SELECT name, object_id as id FROM wphj_terms AS post_taxonomy_category_tbl_terms INNER JOIN wphj_term_taxonomy AS post_taxonomy_category_tbl_termtaxonomy ON post_taxonomy_category_tbl_termtaxonomy.term_id = post_taxonomy_category_tbl_terms.term_id AND post_taxonomy_category_tbl_termtaxonomy.taxonomy = 'category' INNER JOIN wphj_term_relationships AS rel_post_taxonomy_category_tbl ON post_taxonomy_category_tbl_termtaxonomy.term_taxonomy_id = rel_post_taxonomy_category_tbl.term_taxonomy_id) AS post_taxonomy_category_tbl
ON post_taxonomy_category_tbl.ID = posts_post.id
LEFT JOIN (SELECT posts_post_imgposts.guid AS guid, posts_post_imgpostmeta.post_id AS post_id
FROM wphj_postmeta AS posts_post_imgpostmeta
INNER JOIN wphj_posts AS posts_post_imgposts
ON posts_post_imgpostmeta.meta_value = posts_post_imgposts.ID
WHERE posts_post_imgpostmeta.meta_key = '_thumbnail_id' ) AS posts_post_img
ON posts_post_img.post_id = posts_post.ID
WHERE 1=1
AND posts_post.post_type = 'post'
答案 0 :(得分:0)
您可以尝试使用此代码,我在本地安装的sequal pro上运行它,并且我认为它可以工作,因为我认为您希望它能够正常工作。
print mx * v.reshape(-1,1)
[[ 0]
[ 35]
[105]
[245]]