mercredi 19 août 2015

MYSQL select random rows with fewer and higher chances to be selected

In my database I have a table with usernames and an amount of tickets per user. The table looks like this:

<table>
<tr>
<th>username</th>
<th>tickets</th>
</tr>
<tr>
<td>user 1</td>
<td>5</td>
</tr>
<tr>
<td>user 2</td>
<td>12</td>
</tr>
</table>

Now I'm looking for a query to select 3 random users whereby the chances to be selected are higher if this user has more tickets.

If I add up all tickets of the whole table and I divide the tickets per user by this result, I have the chances per user to be selected.

How can I put all this in a query with as a result 3 random users?




Aucun commentaire:

Enregistrer un commentaire