query-8f7ae92bf32c279aa2c9d4237047dfb9

rq turtle/ttl

Films: One film per row; cells with > 1 valueI've adapted the following miserably little query of films made in 2017. I'm looking for 5 core items in columns: country, genre, language, director and script writer. Each film should have ONE row (at present, some have 20!). All 5 columns can have more than one value eg the film could be in more than one language. I've tried adding two things: GROUP_CONCAT and Group by, but the query fails. The separator should be a $$$ rather than a comma (end result = csv file). Adding GROUP_CONCAT to every one of the 5 items seems repetitive, and I'm sure there's a simpler way of doing this? If there's documentation on GROUP_CONCAT, please let me know.

Use at

PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX bd: <http://www.bigdata.com/rdf#>
SELECT DISTINCT ?item ?itemLabel ?languageLabel ?countryLabel ?directorLabel ?genreLabel ?scriptLabel (GROUP_CONCAT(DISTINCT(str(?genre)); separator="$$$ ") as ?genre)

WHERE {
  ?item wdt:P31 wd:Q11424.
  ?item wdt:P577 ?pubdate.
    OPTIONAL { ?item wdt:P495 ?country }
    OPTIONAL { ?item wdt:P136 ?genre }
    OPTIONAL { ?item wdt:P364 ?language }
    OPTIONAL { ?item wdt:P57 ?director }
    OPTIONAL { ?item wdt:P58 ?script }

  FILTER((?pubdate >= "2017-01-01T00:00:00Z"^^xsd:dateTime) && (?pubdate <= "2017-12-31T00:00:00Z"^^xsd:dateTime))
  SERVICE wikibase:label { bd:serviceParam wikibase:language "cy,en,de,fr,ru,bg,cs,po,pl,nl,sl,eun,ro,oc,az,ast,my,tl,ga,br,it,cs,hu,ca,es,no,nn,gl". }
}

GROUP BY ?genre ?item ?itemLabel
ORDER BY ?item

Query found at