0
如何对mysql数据库进行查询,以降序对结果进行排序,条件是列表中出现的特定项目首先出现。 例如,我有一张贴有类别映射表'post_category_mapping'中的类别的帖子'post_feeds'文章。我尝试按排序顺序检索表'post_feeds'中的所有帖子,但条件是list_id存在于列表中。以IN运算符排序
我试图通过这个查询做到这一点:
SELECT DISTINCT post_category_mapping.post_id,
posts_feeds.post_title
FROM post_category_mapping
INNER JOIN posts_feeds
ON post_category_mapping.post_id = posts_feeds.post_id
ORDER BY CASE WHEN post_category_mapping.category_id IN (1,6)
THEN posts_feeds.id END DESC,
posts_feeds.id DESC"
看到这个:http://stackoverflow.com/questions/35109084/conditional-order-by –