0

I broke my head about this, but couldn't find a solution. Let's take the following example:

There is a game and a user can find stuff. But you can't find all the stuff equally. So there is a table with the items, and thereby a number (let's say between 0 and 5) that will say how much the chance is that this will be found.

So if you have 3 items from 5, 2 and 3:

  • First item: 50% chance ( 5/(5+2+3) )
  • Second item: 20% chance ( 2/(5+2+3) )
  • Third item: 30% chance ( 3/(5+2+3) )

Is this possible with just SQL or do you really need another language like PHP too?

BenMorel
  • 31,815
  • 47
  • 169
  • 296
Olivier Van Bulck
  • 633
  • 1
  • 6
  • 19

1 Answers1

0

Try this

SELECT item , (itemNumber / (Select SUM(itemNumber) from itemTable) )*100
FROM itemTable
Mudassir Hasan
  • 26,910
  • 19
  • 95
  • 126
  • Yes, that calculates the percentages and I know how to do that, but I want to select a random row from the table, dependent on the percentage of chance to be selected actually. – Olivier Van Bulck Jan 12 '14 at 13:32