squallleonhart
New Member
- Joined
- Oct 12, 2010
- Messages
- 14
Hello,
I have a query that looks at a couple of tables that have renewal dates for group ID's. Each renewal date is separated into blocks of group ID's, these blocks are given a block ID. My query looks at the tables and based on the renewal date chosen returns the last two blocks, along with the corresponding data, for the groups who have that renewal date. Here is the code that may make more sense:
SELECT [Groups by Renewal Date].RenewalRateEffectiveDate, dbo_BBB_GroupData.blockID, dbo_BBB_GroupData.groupID, dbo_BBB_GroupData.rateChange, dbo_BBB_GroupData.totalCensusEmployeesMedical
FROM [Groups by Renewal Date] INNER JOIN dbo_BBB_GroupData ON [Groups by Renewal Date].groupID = dbo_BBB_GroupData.groupID
WHERE ((([Groups by Renewal Date].RenewalRateEffectiveDate)=[mm/dd/yyyy]) AND ((dbo_BBB_GroupData.blockID) In (SELECT TOP 2 T.blockID FROM dbo_BBB_GroupData T WHERE T.groupID = dbo_BBB_GroupData.groupID ORDER BY T.blockID Desc)));
I would like to create another query that returns the data for the smallest block ID, in other words filtering out the max block ID from the previous query results. I thought this would be really simple, but the code below does not filter anything out so the results of the two queries are the same.
SELECT Last(Last2Blocks.groupID) AS LastOfgroupID, Last2Blocks.blockID, Last2Blocks.rateChange, Last2Blocks.totalCensusEmployeesMedical
FROM Last2Blocks
GROUP BY Last2Blocks.blockID, Last2Blocks.rateChange, Last2Blocks.totalCensusEmployeesMedical;
Any help would be greatly appreciated!
I have a query that looks at a couple of tables that have renewal dates for group ID's. Each renewal date is separated into blocks of group ID's, these blocks are given a block ID. My query looks at the tables and based on the renewal date chosen returns the last two blocks, along with the corresponding data, for the groups who have that renewal date. Here is the code that may make more sense:
SELECT [Groups by Renewal Date].RenewalRateEffectiveDate, dbo_BBB_GroupData.blockID, dbo_BBB_GroupData.groupID, dbo_BBB_GroupData.rateChange, dbo_BBB_GroupData.totalCensusEmployeesMedical
FROM [Groups by Renewal Date] INNER JOIN dbo_BBB_GroupData ON [Groups by Renewal Date].groupID = dbo_BBB_GroupData.groupID
WHERE ((([Groups by Renewal Date].RenewalRateEffectiveDate)=[mm/dd/yyyy]) AND ((dbo_BBB_GroupData.blockID) In (SELECT TOP 2 T.blockID FROM dbo_BBB_GroupData T WHERE T.groupID = dbo_BBB_GroupData.groupID ORDER BY T.blockID Desc)));
I would like to create another query that returns the data for the smallest block ID, in other words filtering out the max block ID from the previous query results. I thought this would be really simple, but the code below does not filter anything out so the results of the two queries are the same.
SELECT Last(Last2Blocks.groupID) AS LastOfgroupID, Last2Blocks.blockID, Last2Blocks.rateChange, Last2Blocks.totalCensusEmployeesMedical
FROM Last2Blocks
GROUP BY Last2Blocks.blockID, Last2Blocks.rateChange, Last2Blocks.totalCensusEmployeesMedical;
Any help would be greatly appreciated!