ORDER BY RAND() seems to be less than random

后端 未结 2 1220
梦如初夏
梦如初夏 2021-01-18 21:36

I have a fairly simple SQL (MySQL):

SELECT foo FROM bar ORDER BY rank, RAND()

I notice that when I refresh the results, the randomness is s

2条回答
  •  离开以前
    2021-01-18 21:50

    The RAND() can not be refresh for each row. A possible solution might be:

    SELECT foo FROM bar ORDER BY rank, CHECKSUM(NEWID())
    

提交回复
热议问题