开发者

Mysql : Sort by id DESC but also sort by another column and ignore value 0

开发者 https://www.devze.com 2023-02-13 00:43 出处:网络
Im trying to figure out if this is possible. I want to sort by the id in DESC order, but there are certain records in the table that need to be pushed to the top.

Im trying to figure out if this is possible.

I want to sort by the id in DESC order, but there are certain records in the table that need to be pushed to the top. I tried some ways, here is one ex. Maybe someone can help me out here?

SELECT *
FROM `table`
ORDER BY CASE WHEN index >0
THEN index
END , id DESC
LIMIT 0 , 30

But I cant seem to get t开发者_开发百科he right output.


Almost! Try this:

ORDER BY CASE WHEN index > 0
THEN 0
ELSE 1
END, id DESC
0

精彩评论

暂无评论...
验证码 换一张
取 消