我在上面有我的查询,它可以很好地检索数据,但顺序已关闭。我正在尝试按价格订购结果。不知道我是否需要添加另一个GROUP BY参数,或者是否需要添加另一个联接。还有其他人遇到同样的问题吗?
SELECT wp_posts.ID,wp_postmeta1.meta_value AS sku, wp_postmeta2.meta_value AS Price
FROM wp_posts
LEFT JOIN wp_postmeta wp_postmeta1
ON wp_postmeta1.post_id = wp_posts.ID
AND wp_postmeta1.meta_key = '_sku'
LEFT JOIN wp_postmeta wp_postmeta2
ON wp_postmeta2.post_id = wp_posts.ID
AND wp_postmeta2.meta_key = '_price'
WHERE (wp_posts.post_type = 'product'
AND wp_posts.post_status = 'publish'
AND wp_posts.post_title LIKE '%abi%')
OR (wp_posts.post_type = 'product'
AND wp_posts.post_status = 'publish'
AND wp_postmeta1.meta_value LIKE '%abi%' )
GROUP BY wp_posts.ID
ORDER BY wp_postmeta2.meta_value ASC
LIMIT 15
答案 0 :(得分:0)
使用强制转换固定排序。 按CAST排序(wp_postmeta2.meta_value为无符号)ASC