Created
June 11, 2017 19:09
-
-
Save apphp/62f46e52a0a3e566271726bc8fd336c6 to your computer and use it in GitHub Desktop.
Get Random Record Based on Weight
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- http://www.apphp.com/index.php?snippet=mysql-get-random-record-based-on-weight | |
-- Must have as field named 'weight' | |
SELECT * FROM `table` ORDER BY RAND() * (1 / `weight`) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment