GROUP BY

GROUP BY

Ora che hai imparato a usare una funzione aggregata come COUNT, è ora di combinarla con una funzione SPARQL chiamata GROUP BY.
GROUP BY aggregates data in your dataset, making it easy to run functions like COUNT on groups of data for analysis .

Take for example the query retrieving the number of tennis players on Wikidata. In the following query we add a variable – ?gender – and ask WDQS to show the results grouped by this variable.

Note that the variable used in the GROUP BY modifier must be listed in the SELECT clause.

You may notice that if you sum the count of items of all groups it is lower than the total number counted in the original query (without the gender grouping). This is the case because there are in fact a few tennis players for which no gender information is given. (See OPTIONAL clause)

Skip to content