In all of the examples I've seen of SUBQUERY
, @count
is always used, e.g.,
SUBQUERY(employees, $e, $e.lastName == "Smith").@count > 0
So I have three very closely related questions, which work best as a single StackOverflow question:
- Is there any use for
SUBQUERY
without@count
? If so, I haven't found it. - Can any other aggregates be used with
SUBQUERY
? If so, I haven't been able to get them to work. (See below.) - What exactly does
SUBQUERY
return? The logical thing seems to be a filtered collection of the type of the first parameter. (I'm speaking conceptually here. Obviously the SQL will be something different, as SQL debugging shows pretty plainly.)
This gives an exception, as does every other aggregate I've tried other than @count
, which seems to show that no other aggregates can be used:
SUBQUERY(employees, $e, $e.lastName == "Smith").@avg.salary > 75000
(Let's leave aside for the moment whether this is the best way to express such a thing. The question is about SUBQUERY
, not about how best to formulate a query.)
Mundi helpfully pointed out that another use for SUBQUERY
is nested subqueries. Yes, I'm aware of them and have used them, but this question is really about the result of SUBQUERY
. If we think of SUBQUERY
as a function, what is its result and in what ways can it be used, other than with @count
?
UPDATE
Thanks to Mundi's research, it appears that aggregates like @avg
do in fact work with SUBQUERY
, particularly with an in-memory filter such as filteredArrayUsingPredicate:
, but not with Core Data when the underlying data store is NSSQLiteStoreType
.