Re: How do I write a fetch request that will get the entity with the max value?
Re: How do I write a fetch request that will get the entity with the max value?
- Subject: Re: How do I write a fetch request that will get the entity with the max value?
- From: Charilaos Skiadas <email@hidden>
- Date: Mon, 1 Aug 2005 20:26:36 -0500
On Aug 1, 2005, at 7:42 PM, Scott Ellsworth wrote:
Hi, all.
My World entity has pop and tech int16 attributes. I want to find
the Entity with the largest value of pop+tech/3.
I have read through the NSPredicate BNF doc until I am blue in the
face, but the xcode data modeler does not like anything I have
thrown at it. How do I find the World with the largest value for
pop+tech/3?
The obvious "max(pop+tech/3)" does not work, though weird ones like
"max(pop+tech/3)>7 do not throw a syntax error. It is not the
query I want to do, but it does not throw a syntax error.
I might be completely off the mark here, but anyway these are my 5c:
Well, your query needs to be such that the answer is either a YES or
a NO. In the second case, you are asking it to compute pop+tech/3,
this one value, then take the max of the set consisting of this one
value, which is itself, and then answer YES or NO according to
whether this is bigger or smaller than 7.
What you probably want is to somehow form an array of the values pop
+tech/3 for all instances of World, and then take the max of that,
and then compare the result with the current instance. I have no idea
if this will be possible or not, but I don't think it will be. You
are really asking it to go through the entire collection of instances
of World, before it has any chance of giving you an answer, so this
seems hard.
One possibility would be to have another entity, with a to-many
relationship to worlds with an inverse. This could act as your entire
collection of Worlds (maybe you could call it Universe or
something :-) ).
Then, supposing the relationship is called "worlds", and its inverse
is called "universe", and assuming further that you have a derived
value res=pop+tech/3, you could maybe try something like:
"res=max(universe.worlds.res)"
well, you might want to worry about the fact that res is not an
integer anymore, unless you are doing integer division with 3. If it
is float you probably want to be more flexible about equality.
As usual, not actually tried it, just a suggestion.
I have done harder things than this with the data modeler, but this
one has me stumped. Anyone happen to know the answer?
Scott
Haris
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden