Already returning distinct values, need counts for each respective value as well

007programmer
007programmer used Ask the Experts™
on
If I run this against a ML database:

let $audiences :=
for $doc in xdmp:directory("/myDirectory/")
where fn:contains($doc, 'BLAH')
return $doc/audience

for $audience in distinct-values($audiences)
return $audience

This will return the disctinct values, however I also want the counts for each of these values
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Information Architect
Top Expert 2006
Commented:
try this as the return

return concat($audience, ' (', count($doc[audience = $audience]), ') ')

it will give you the distinct values and the number between brackets

Author

Commented:
I've requested that this question be deleted for the following reason:

No suitable answers
Gertone (Geert Bormans)Information Architect
Top Expert 2006

Commented:
Hi,
The least you can do is respond to my suggestion,
I definitely gave you code to test and debug
So I have to object closing this
Gertone (Geert Bormans)Information Architect
Top Expert 2006

Commented:
My next suggestion would have been to have the distinct-values() on the text nodes that are descendents of the $audience. Some XQuery processors are tricky about that.
But first of course you could have tried the suggestion and could have given feedback about this.
Note that you sollicited for my time, which I voluntarily gave you, the least I can demand is feedback
Gertone (Geert Bormans)Information Architect
Top Expert 2006

Commented:
My recommendation:
Accept http:#a37993619
The question was "This will return the disctinct values, however I also want the counts for each of these values "
That is exactly (I tested prior to posting) what the code I posted does

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial