开发者

SQL syntax for ORDER BY random sublevel?

开发者 https://www.devze.com 2023-02-14 03:09 出处:网络
I need help with the dumbest of questions. I want to make a query ordered by one field, named \'client_level\'. The table has something like 400 rows, and client_level possible values are NULL, 1,2,3,

I need help with the dumbest of questions. I want to make a query ordered by one field, named 'client_level'. The table has something like 400 rows, and client_level possible values are NULL, 1,2,3,4 and 5.

Those are client levels. I want to order all clients by their client_level. Clients leveled 5 should go before clients level 4 and so on.. that is easy.

SELECT * FROM client ORDER BY client_level DESC;

The problem is.... I want to randomize each sub-group of clients to make the order inside a client level different each time, and therefore, equi开发者_如何学Pythonlibrated over time and this query does not work as I think it should.

SELECT * FROM client ORDER BY client_level, RAND() DESC;

I am sure there must be a way, thank you for your answers. kind regards,


I think you just misplaced the DESC. try:

SELECT * FROM client ORDER BY client_level DESC, RAND();
0

精彩评论

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