开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜