Table: FooData
ID Count 1 54 2 42 3 33 4 25 5 16 6 9 8 5 9 3 10 2
I want to fetch the record that sum of Count column is greater than a certain percentage like 90.
For this example, the sum of all the records is 189, and 90% of it is 170.1, we can see the sum from ID 1 to 6 is 179, and it is greater than 170.1 so the record ID 6 should be returned.
btw, temporary table is not allowed because I need to do it in a function.
Try this:
But also be aware of the potential performance issue with triangular joins in running totals.