Row-by-row addition to a limit

0 pts.
Tags:
Desktops
Management
Microsoft Windows
OS
Security
Servers
SQL Server
I have a table containing the fields Stand, Species, Diameter, TreesPerAcre. I need to retrieve the rows from each Stand where the TreesPerAcre sum to between 20 and 25. In the following subset only the first five rows should return. Stand Species Diameter TreesPerAcre 101 DF 48 2 101 NF 27 3 101 DF 24 10 101 DF 22 6 101 PP 18 3 101 DF 16 5 The problem is getting a row-by-row addition to a limit. Using HAVING SUM(TreesPerAcre) BETWEEN 20 AND 25 doesn't work because SUM(TreesPerAcre) for Stand 101 = 29. I surely hope someone has a clue for me.
ASKED: October 25, 2005  2:10 PM
UPDATED: October 26, 2005  2:09 PM

Answer Wiki

Thanks. We'll let you know when a new response is added.

I guess I’m not understanding the question. You say you only want retrieve the rows if the sum is between 20 and 25, which means your query SHOULDN’T return the rows for Stand 101, because they add up to 29. 29 is clearly outside your range, but you seem to be saying you think those rows should be returned. What am I missing?

Discuss This Question: 1  Reply

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • Larryv
    Thanks for the reply. You're not missing anything, I didn,t say it clearly. I need to retrieve the first 5 rows by adding TreesPerAcre row-by-row until the total is between 20 and 25. This is actual data from a forest inventory and the manager needs the first set of rows from each stand where the total TreesPerAcre is between 20 and 25. The number of rows returned will vary from one stand to another. There are about 500,000 rows to process. I am working on a WHILE but have not got it yet. Hope you can help.
    0 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following