Good morning,


I'm running third-party software (Affinium Campaign) with a DB2 backend, but do not have access to the DB2 version.

I have a table that contains unique IDs, and each ID belongs to exactly one Group. The table structure is simply: ID, Group.

I'm trying to write a statement that will perform a tablesample on the table, but will do so evenly within the groups. I'm hitting a wall for some reason.

For example, the following statement does a 20% sample on my table, but I need to take a 20% sample of each group:

SELECT ID FROM ID_GROUP_TB TABLESAMPLE BERNOULLI(20.0);

Does anyone have any ideas on how to perform this? The set of Groups is not repeatable, so I can't do it manually with WHERE statements to get the needed result.


Thank you!