mangle icon indicating copy to clipboard operation
mangle copied to clipboard

How to do `count`

Open maxott opened this issue 1 year ago • 1 comments

I'm stuck with a very simple problem but can't find a solution. All I want is to return the number of unique facts/records found.

Let's assume I have stored the names and sizes of images, but may have stored some of them multiple times. How can I find out how many unique images do I have. What I came up with is rather complex (group_by requires me to have an aggregation function setting something, therefore the unnecessary Count)

unique(N, Count) :-
    images(N, _),
    |> do fn:group_by(N),
       let Count = fn:count().

query(Count) :-
    unique(_, _),
    |> do fn:group_by(),
       let Count = fn:count().

maxott avatar Sep 06 '24 06:09 maxott

You could use fn:collect_distinct(N) to get a list of unique values, and then take the length of that list.

We are missing fn:count_distinct(), I will add it.

burakemir avatar Sep 06 '24 07:09 burakemir

Closing, please reopen if fn:count_distinct() does not address your use case.

burakemir avatar Nov 01 '24 12:11 burakemir