Group the results by one or more variables
Examples
spq_init() %>%
spq_add("?item wdt:P361 wd:Q297853") %>%
spq_add("?item wdt:P1082 ?folkm_ngd") %>%
spq_add("?area wdt:P31 wd:Q1907114") %>%
spq_label(area) %>%
spq_add("?area wdt:P527 ?item") %>%
spq_group_by(area, area_label) %>%
spq_summarise(total_folkm = sum(folkm_ngd))
#> PREFIX wd: <http://www.wikidata.org/entity/>
#> PREFIX wdt: <http://www.wikidata.org/prop/direct/>
#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
#> SELECT ?area ?area_label (SUM(?folkm_ngd) AS ?total_folkm)
#> WHERE {
#>
#> ?item wdt:P361 wd:Q297853.
#> ?item wdt:P1082 ?folkm_ngd.
#> ?area wdt:P31 wd:Q1907114.
#> OPTIONAL {
#> ?area rdfs:label ?area_labell.
#> FILTER(lang(?area_labell) IN ('en'))
#> }
#>
#> ?area wdt:P527 ?item.
#> BIND(COALESCE(?area_labell,'') AS ?area_label)
#>
#> }
#> GROUP BY ?area ?area_label
#>