SQL syntax for ORDER BY random sublevel?
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();
精彩评论