select random value based on probability chance
问题 How do I select a random row from the database based on the probability chance assigned to each row. Example: Make Chance Value ALFA ROMEO 0.0024 20000 AUDI 0.0338 35000 BMW 0.0376 40000 CHEVROLET 0.0087 15000 CITROEN 0.016 15000 ........ How do I select random make name and its value based on the probability it has to be chosen. Would a combination of rand() and ORDER BY work? If so what is the best way to do this? 回答1: You can do this by using rand() and then using a cumulative sum.