gpt4 book ai didi

mysql - Order By 不适用于 Left Join -MySQL/Wordpress

转载 作者:行者123 更新时间:2023-11-29 17:23:53 25 4
gpt4 key购买 nike

我上面有我的查询,它可以很好地检索数据,但排序已关闭。我正在尝试按价格对结果进行排序。不确定我是否需要添加另一个 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

最佳答案

使用强制转换修复了排序。按 CAST 排序(wp_postmeta2.meta_value 作为无符号)ASC

关于mysql - Order By 不适用于 Left Join -MySQL/Wordpress,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51080565/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com