Not an easy problem. It seems a variation of the well known 'back pack"
problem, which is a complex algorithm (and generally, people only use an
heuristic, giving an approximate solution, rather than the exact algorithm).
Indeed, define, for each record, the variable x such that x=0 if we
don't pick the record and x=1 if we pick it.
We want:
Optimize (Maximize)
SUM( x ) ' the sum is about those x=1,
so this is the total number of
records we picked
under
SUM( x * Score ) = 45 * SUM( x )
' the mean constraint
and
x element_of {0, 1}
but that is the same as:
(since MAX { cte*z } = cte* MAX{ z } )
Optimize
SUM( x * Score )
under
SUM( x * Score ) = 45 * SUM( x )
and
x element_of {0, 1}
which seems harder than the back-pack problem:
Optimize
SUM(x * Score)
under
SUM( x* Score ) <= W_constant
and
x element_of {0, 1}
So, for an exact solution, I would look for an algorithm based on Balas
family of algorithms, or other dynamic approach, but for all I know, that is
far stretched to do by SQL, unless you consider brutal implicit enumeration.
Sorry, but still, I can be wrong, it may just look harder than the backpack,
problem, while be easier, after all.
Vanderghast, Access MVP