Reputation: 83
Hi I'm using SPARQL to query the LMDB ( http://data.linkedmdb.org/snorql/ ) and I've been trying to also get the number of instances when some query results are returned. I've been trying to add (COUNT(?something) AS ?somethingElse)
and then either GROUP or ORDER BY
to my queries but then the variable ?somethingElse
replaces all of the other results. I think that the best way would be to use UNION
and get the results in separate row, which has nothing to do with the others but for some reason I can't find the right solution.
My Query:
PREFIX mov: <http://data.linkedmdb.org/resource/movie/>
SELECT DISTINCT ?Names WHERE
{ ?link mov:actor_name 'guy boyd' .
?movie mov:actor ?link;
mov:actor ?Link_To_Actor_Page.
?Link_To_Actor_Page mov:actor_name ?Names. }
If you run this query everything is fine but when if you add (COUNT(?Names) AS ?total)
only ?total
is printed out. So I guess my questions is how can I print out as many variables as I want and get the COUNT(?something)
as a separated column. Basically without the COUNT(?)
replacing every other ?variable
in the query.
Upvotes: 1
Views: 921
Reputation: 1481
Morning,
Simply add what you need to the SELECT
method. The number of asked elements is not limited.
Here is your example corrected :
PREFIX mov: <http://data.linkedmdb.org/resource/movie/>
SELECT DISTINCT ?Names (COUNT(?Names) as ?total)
WHERE {
?link mov:actor_name 'guy boyd' .
?movie mov:actor ?link ;
mov:actor ?Link_To_Actor_Page .
?Link_To_Actor_Page mov:actor_name ?Names .
} GROUP BY ?Names
Here is the location of the SPARQL Endpoint : http://www.linkedmdb.org/snorql/
I hope it will help you and not simply give you the answer without understanding it.
Upvotes: 1