SPARQL - How do you use an account?

I have this request

SELECT ?s WHERE {?a <http://xmlns.com/foaf/0.1/topic_interest> ?s} 

which returns

 aaa aaa aaa bbb bbb ccc 

However, I want to display it as

 aaa | 3 bbb | 2 ccc | 1 

I am using dotnetrdf. This is what I tried

 SELECT (COUNT(*) AS ?s) WHERE {?a <http://xmlns.com/foaf/0.1/topic_interest> ?s} 

and that just gives me the number of rows, which is 3080.

Can you tell me how to do it right?

thanks

+4
source share
1 answer

This is because COUNT (*) simply counts the result rows for each group.

If the query does not have a GROUP BY clause, then there is one implicit group of all results, so you just get the number of rows.

If you add GROUP BY to your query, as in the following example, you should get the desired result:

 SELECT (COUNT(*) AS ?count) WHERE { ?a <http://xmlns.com/foaf/0.1/topic_interest> ?s} } GROUP BY ?s 
+5
source

Source: https://habr.com/ru/post/1396880/


All Articles