2

I am trying to get some municipalities and their population (P1082) over the years using SPARQL in Wikidata. The query I am using works, but I do not know how to convert the years of the population figures into columns, so that I only have a single unique item. The structure I would want to be returned in the query is:

place    placeLabel  1815 1830 1840 ... 2019  2020  parentPlaceLabel
wd:Q9908 Bloemendaal 1458 1748 2058 ... 23410       Q101626200
wd:Q9928 Heemstede   2186 2227 2332 ... 27286 27234 Q101626200

I have been reading about BIND but find it difficult to adapt it to the code since the code I am using gets all the population point in time (P585) qualifier values.

logi-kal
  • 7,107
  • 6
  • 31
  • 43
JAT86
  • 997
  • 12
  • 24
  • 3
    that is impossible in SPARQL - all columns have to be specified explicitly in the projection part of the query - there is no pivot operator nor is there an explode function or the like. I'm pretty sure you don't know all years in advance given that the years might vary per municipality - moreover, you'd have to bind each year value then in a separate `OPTIONAL` clause to their corresponding var name. My suggestion, get all the data and format it in your client code, there is no other way – UninformedUser Feb 18 '22 at 15:31

0 Answers0