glitter icon indicating copy to clipboard operation
glitter copied to clipboard

What about WITH

Open maelle opened this issue 3 years ago • 2 comments

E.g.

Fictional characters whose birth/death date is in the current decade

SELECT DISTINCT ?character ?characterLabel ?birth ?death WITH {
  # Fictional character subclasses as a named subquery
  SELECT ?fictiontype WHERE {
    ?fictiontype wdt:P279* wd:Q95074. hint:Prior hint:gearing "forward".
  }
} AS %i
WHERE
{
  INCLUDE %i
  ?character wdt:P31 ?fictiontype.
  # Date of birth
  { ?character wdt:P569 ?birth . }
  # Date of death
  UNION { ?character wdt:P570 ?death . }
  # Get actual decade to compare with dates
  BIND(xsd:integer(YEAR(NOW())/10) as ?actual_decade).
  # Only show characters born or deceased in the current decade
  FILTER(xsd:integer(YEAR(?birth)/10) = ?actual_decade || xsd:integer(YEAR(?death)/10) = ?actual_decade)
  SERVICE wikibase:label {
    bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" . 
  }
} ORDER BY ?birth ?death

maelle avatar Mar 10 '22 11:03 maelle

related to complex queries / subqueries in my opinion, so I'd drop it for now?

lvaudor avatar Mar 10 '22 12:03 lvaudor

maybe add these considerations to the new vignette about complex queries ?

lvaudor avatar May 10 '23 07:05 lvaudor