I'd like to query a very large table with millions of records. The query should return the latest transactions for all parts. The final report shows how many quantity on hand for each month.
I give the following example for Part SC198 and SC216. Actually we have thousand of parts.
[Part Number] [Quantity on Hand] [Updated Date]
SC198 30 1/2/2002
SC198 50 1/5/2003
SC198 60 2/3/2007
SC198 70 2/6/2008
SC198 100 3/6/2010
SC198 200 5/2/2010
SC216 10 1/2/2003
SC216 20 2/3/2007
SC216 50 1/1/2010
SC216 80 3/2/2010
SC216 60 4/5/2010
The result for updated date before 3/1/2010 should be
SC198 70 2/6/2008
SC216 50 1/1/2010
.....
.....
The result for update date before 4/1/2010 should be
SC198 100 3/6/2010
SC216 80 3/2/2010
....
....
The final report should looks like this,
[Part Number] Jan Feb March April May ...
SC198 70 70 100 100 200
SC216 50 50 80 60 60 ...
I tried Max
and top(1)
, it didn't return the right result, please help me.