繁体   English   中英

升序排序列,但我希望0排在最后并且使用mysql随机

[英]Sort column ascending but I want 0 to come last and RANDOMLY using mysql

我需要按升序从MySQL表中获取数据,但零值最后出现且随机出现

现在这是我的按条件排序。这不起作用

ORDER BY sortorder=0 RAND(),sortorder

使用条件排序

select *
from table
order by column > 0 desc, column asc, rand()

在末尾添加rand()

演示版

或者你可以使用union

(select * from table where column > 0 order by column asc)
union all
(select * from table where column = 0 order by rand())

演示版

如果要从mysql随机获取数据,则零值排在最后。 您可能需要尝试以下方法:

SELECT * FROM table ORDER BY `column` = 0, rand();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM