tags:

views:

27

answers:

1

Let say i want to store several dataset ie

78 94 33 22 14 55 18 10 11

44 59 69 79 39 49 29 19 39

And later on i would like to be able run queries that will determine the frequency of certain number. What would be the best way to this? What would be table structure to make a fast query.

Please be specific as you can be.

A: 

To get the counts, you can run a query such as:

SELECT value, COUNT(*) from table_of_values GROUP BY value

Placing an index on the single integer value column is pretty much all you can do to speed that up.

You could of course also just keep a table with every two-digit value and a count. You will have to pre-fill the table with zero counts for every value.

Then increment the count instead of inserting:

UPDATE table_of_values SET count = count + 1 WHERE value = (whatever)
Joe Koberg
How about storing all of them on the same table but in separate fields? so each value ie"44" would be in a seperate field ?
Why not. There are only 100 two-digit values. A 100-column table is not that big a deal. But lets say you are taking updates from a large number of updaters. Multiple rows will probably allow parallelism, because each row can be locked/updated separately.
Joe Koberg