I have a query that outputs results as follows:
Person Food
====== ======
Abner Apple
Beth Banana
Beth Peach
Carlos Grape
Carlos Kiwi
Carlos Strawberry
. . . .
Namely, it associates a person with one or more foods. I'd like the functionality of an aggregate function to choose a food, but none of the built-in aggregates (SUM, MAX, MIN,etc.) really applies to the situation.
If I have a function F() that, given a list of foods, either:
- provides an ordered list of foods based on some optimization
- provides the optimal unique choice from the list
is there any way I can apply a GROUP BY onto it directly?
Does anyone have an example of a query that does this some other way, in case this is a pipe dream?
= = = =
EDIT: Let's say that out of the options shown above, the optimal list is {Kiwi, Grape, Banana, Strawberry, Apple, Peach}, then the output should say:
Abner Apple
Beth Banana
Carlos Kiwi
i.e., one record per Person, and the Food for each is the first occurrence in the optimal list of a Food associated to that Person in the original table.