Back
Close

An introduction to RDF querying in SPARQL

Zwifi
1,311 views

Grouping results

Aggregation

Aggregation and projection
PREFIX yaco: <https://www.irit.fr/recherches/MELODI/ontologies/cinema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT ?name (COUNT(?role) AS ?nb_roles)
WHERE {
?actor rdf:type yaco:Actor;
rdfs:label ?name;
yaco:playsRole ?role.
} GROUP BY ?actor
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Who is he oldest actor?
PREFIX yaco: <https://www.irit.fr/recherches/MELODI/ontologies/cinema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT ?name (MIN(?year) as ?minYear)
WHERE {
?actor rdf:type yaco:Actor;
rdfs:label ?name;
yaco:birthYear ?year.
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Group filtering

Who are the actors who played in at least two movies?
PREFIX yaco: <https://www.irit.fr/recherches/MELODI/ontologies/cinema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT ?name
WHERE {
?actor rdf:type yaco:Actor;
rdfs:label ?name;
yaco:playsRole ?role.
} GROUP BY ?actor
HAVING (COUNT(?role) > 2)
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Create your playground on Tech.io
This playground was created on Tech.io, our hands-on, knowledge-sharing platform for developers.
Go to tech.io
codingame x discord
Join the CodinGame community on Discord to chat about puzzle contributions, challenges, streams, blog articles - all that good stuff!
JOIN US ON DISCORD
Online Participants