我有一个租赁自定义帖子类型。 租金有价格,价格存储在租赁表中。 租赁还有一个元键"特色"。它的值为" on"或"关闭"。 到目前为止,我可以设法按功能排序租金,然后按价格排序。所以特色商品首先出现,然后其他商品和商品按价格排序。 这很好,但我的客户提出了另一个想法。 特色租赁支付每月价格,并且始终显示价格最低的那些是不公平的。 所以我应该按日期订购特色商品,他们会先订购,然后是其他商品,但其他商品将按价格订购。
我认为可以用子查询完成,但我不知道如何。
这是我现在运行的查询:
SELECT SQL_CALC_FOUND_ROWS wp_posts.*,
FROM wp_posts
INNER JOIN wp_postmeta ON ( wp_posts.ID = wp_postmeta.post_id )
INNER JOIN wp_st_rental as tb ON wp_posts.ID = tb.post_id
WHERE 1=1 AND
( wp_posts.ID NOT IN ( SELECT object_id FROM wp_term_relationships
WHERE term_taxonomy_id IN (253) ) ) AND
( wp_postmeta.meta_key = 'is_featured' ) AND
wp_posts.post_type = 'st_rental' AND ((wp_posts.post_status = 'publish'))
AND wp_posts.ID IN (SELECT post_id FROM wp_st_location_relationships
WHERE 1=1 AND post_type IN ('st_rental')) GROUP BY wp_posts.ID
ORDER BY wp_postmeta.meta_value DESC, CAST(st_rental_price as DECIMAL) ASC
LIMIT 0, 350
SELECT SQL_CALC_FOUND_ROWS wp_posts.*,
FROM wp_posts
INNER JOIN wp_postmeta ON ( wp_posts.ID = wp_postmeta.post_id )
INNER JOIN wp_st_rental as tb ON wp_posts.ID = tb.post_id
WHERE 1=1 AND
( wp_posts.ID NOT IN ( SELECT object_id FROM wp_term_relationships
WHERE term_taxonomy_id IN (253) ) ) AND
( wp_postmeta.meta_key = 'is_featured' ) AND
wp_posts.post_type = 'st_rental' AND ((wp_posts.post_status = 'publish'))
AND wp_posts.ID IN (SELECT post_id FROM wp_st_location_relationships
WHERE 1=1 AND post_type IN ('st_rental')) GROUP BY wp_posts.ID
ORDER BY wp_postmeta.meta_value DESC, CAST(st_rental_price as DECIMAL) ASC
LIMIT 0, 350
你能帮我修改一下,以便特色首先出现,按日期排序,然后是其他的,按价格排序。 谢谢!