来自wordpress的assum表mysql如下:
post_id | meta_key | meta_value
19 | poster_url | http://exampleimage.com
19 | vote_average | 7.5
我尝试过使用
SELECT * FROM (Select ID,post_date,post_date_gmt,post_content,post_title,post_status,post_name,post_type,meta_key,meta_value as picture from get_movies where meta_key='poster_url' and post_status='publish' and post_type='post') as a,
(Select meta_value as rate from get_movies where meta_key='vote_average' and post_status='publish' and post_type='post') as b
但结果重复并错过了'费率'.. 在这种情况下,我只需要互相制作别名..比如poster_url = picture,和vote_average = rate
有可能吗?
答案 0 :(得分:0)
出于某种原因,我认为这可能是你想要的:
Select ID, post_date, post_date_gmt, post_content, post_title,
post_status, post_name, post_type,
max(case when meta_key = 'poster_url' then meta_value end) as picture,
max(case when meta_key = 'vote_average' then meta_value end) as rating
from get_movies
where post_status = 'publish' and post_type = 'post' and
meta_key in ('poster_url', 'vote_average')
group by ID, post_date, post_date_gmt, post_content, post_title,
post_status, post_name, post_type;
它返回两个不同列中的元键值。