G
Guest
I have a question about a query I'm trying to help a co-worker write.
I'll make the scenario as simple as possible so we'll use a single example table with two columns
item valu
-----------------------
1 6
2 1
3 1
4
5 5
6 5
7
8
Here we have two columns: an item number and a value. The total sum of the values in this example is 100. I need to write a query to return those records that make up 80% of the total VALUE of the records in the table. So, in this example, I would expect a result set with 3 records (items 1, 2 and 3)
I've been able to do this programmatically with ASP (vbscript, by looping through the recordset and calculating a rolling sum to compare to the total sum) and I've also been able to do this in SQL Server (using a cursor to walk through each of the records and calculate a rolling sum, similar to doing it in ASP for example)
So far I've had no luck at all with Access, as it doesn't seem to support a mechanism to calculate a rolling sum as we traverse the "recordset". Access doesn't seem to support the cursor syntax I used in SQL Server either
Any ideas
TIA - Tom
I'll make the scenario as simple as possible so we'll use a single example table with two columns
item valu
-----------------------
1 6
2 1
3 1
4
5 5
6 5
7
8
Here we have two columns: an item number and a value. The total sum of the values in this example is 100. I need to write a query to return those records that make up 80% of the total VALUE of the records in the table. So, in this example, I would expect a result set with 3 records (items 1, 2 and 3)
I've been able to do this programmatically with ASP (vbscript, by looping through the recordset and calculating a rolling sum to compare to the total sum) and I've also been able to do this in SQL Server (using a cursor to walk through each of the records and calculate a rolling sum, similar to doing it in ASP for example)
So far I've had no luck at all with Access, as it doesn't seem to support a mechanism to calculate a rolling sum as we traverse the "recordset". Access doesn't seem to support the cursor syntax I used in SQL Server either
Any ideas
TIA - Tom