March 5, 2008 at 7:26 am
Hi,
I have a table with columns accountid,date, quantity and price. For generation of a report in need to sum the quantity. But i need to stop summing the quantity once the quantity =2000000 and at that date i need to find (quantity* price) for each id.
Please help me in writing a query.
Thanks
March 5, 2008 at 7:31 am
Use your normal sum, but add a having(sum()) >= xxx and order by date.
March 5, 2008 at 8:28 am
Thanks for your response.
I have already tried that option.
But what i actually required is that, each day there are number of entries for quantity.
Quantity mean "shares" a accountid makes. So i have to find (quantity* price) for each id, whose id have a profitablility of $100 shares during their first 2,000,000 shares of their trading.
March 5, 2008 at 11:33 am
I could be wrong, but this sounds like a "running total" problem with an additional SELECT to find the 2 million mark... please see the following...
http://www.sqlservercentral.com/articles/Advanced+Querying/61716/
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply