I have a table which looks like that:
id: primary key
content: varchar
weight: int
What I want to do is randomly select one row from this table, but taking into account the weight. For example, if I have 3 rows:
id, content, weight
1, "some content", 60
2, "other content", 40
3, "something", 100
The first row has 30% chance of being selected, the second row has 20% chance of being selected, and the third row has 50% chance of being selected.
Is there a way to do that? If I have to execute 2 or 3 queries it's not a problem.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…