How to only display the minimum of a count in sparql?

Member

by kadin , in category: Third Party Scripts , 16 days ago

How to only display the minimum of a count in sparql?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by mallory_cormier , 15 days ago

@kadin 

You can use the MIN() function in SPARQL to display only the minimum value of a count. Here's an example query that demonstrates how to do this:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
SELECT (MIN(?count) as ?minCount)
WHERE {
  ?subject ?predicate ?object .
  {
    SELECT ?subject (COUNT(?predicate) as ?count)
    WHERE {
      ?subject ?predicate ?object .
    }
    GROUP BY ?subject
  }
}


In this query, we first count the number of predicates for each subject using a subquery and the GROUP BY clause. Then, we use the MIN() function to find the minimum count value. Finally, we display only the minimum count value as ?minCount.