I'm trying to build a query (Without having to dump this into a ADODB recordset and process through VBA...)
I have four main Columns for the expected output (there are some others but those can be easily added) however I cannot see this query visually... the two important columns are...
M_Date is the date that this certain Item is going to go out
D_Date is the last day that M_Date was updated
Basically, this data changes on a WEEKLY basis... sometimes older M_Dates are not included because those dates have passed now...
I want to write a query that gives me the results for the MAX D_Date for EACH M_Date pairing (I only want the most recent changes for EACH mailing date because its the most updated figures)... This feels very multi-dimensional to me...
CODE
SELECT MAX(PH.D_Date), PH.M_Date, PH.Description, PH.Projected_Quantity
FROM P_History_t as PH
GROUP BY M_Date
HAVING MAX(D_Date)
Obviously this does not give me the results I wish and will not fire off due to using Grouping without aggregate functions on each coulmn, but I'm stumped with just seeing how this can be done... If I could only see a visual in a way that I could twist I could write this but I feel like I'm at the bottom of a well on this one... Group By Having comes to mind but Havn't played around too much in grouping but it feels like the way to go... any better approaches or should I stick with grouping and dive in a bit more?
*EDIT* Forgot to mention that, some of these M_Dates share multiple Dates with Other Items (Basically, Description of 'Item One' could have 3 different D_Dates but 'Item Two' could have only 2 D_Dates)... To make this even more complicated of course. Basically I need to know how to get to the: Highest D_Date for each M_Date for each Description where an M_Date can have Different Descriptions (Each one having its own record in this query)
This post has been edited by mohgeroth: 12 Jun, 2009 - 06:08 PM