Query Commands
Query commands define the query type, such as SELECT, ASK, CONSTRUCT, or DESCRIBE, which specify a set of results to return from a graph, or specify an update operation that defines some query result set to update. Depending on the type of query, the SPARQL statement specifying a query command can include graph and patterns or templates, variables, and functions or expressions that specify criteria for matching data or perform calculations on query results.
Examples
In the following example SPARQL statement, the SELECT query includes a WHERE clause and then specifies the variables and data values to appear in query results. The SPARQL statement also includes a SUM aggregate function to calculate and return the total quantity of tickets sold in the final result.
SELECT ?event ?category (sum(?qty) as ?total_tickets) FROM <tickit> WHERE { ?sales <qtysold> ?qty . ?sales <eventid> ?eventid . ?eventid <eventname> ?event . ?eventid <catid> ?catid . ?catid <catname> ?category . } GROUP BY ?event ?category ORDER BY ?total_tickets LIMIT 10
In the following example, the CONSTRUCT query includes a template used to define the triples stored in a new graph:
CONSTRUCT { GRAPH <ages> { ?person <age> ?age . } } WHERE { GRAPH <tickit> { SELECT ?person ((YEAR(?date))-(YEAR(xsd:dateTime(?birthdate))) AS ?age) WHERE { ?person <birthday> ?birthdate . BIND(xsd:dateTime(NOW()) AS ?date) } } } ORDER BY ?person LIMIT 50