0

Here is the query I am working with:

SELECT DISTINCT ?item ?itemLabel ?rev ?date (group_concat(distinct ?directorLabel ; separator = ", ") as ?directors)
WHERE { 
  ?item wdt:P31/wdt:P279* wd:Q4830453 ;
        wdt:P17 wd:Q30 .
  ?item p:P2139 ?revSt .
  ?revSt pq:P585 ?date.
  FILTER (   YEAR(?date) = 2020 ).
  ?revSt ps:P2139 ?rev .
  ?item p:P3320 ?relationship.
  ?relationship ps:P3320 ?director.
  #Filter Director by no end date
  FILTER NOT EXISTS {?relationship pq:P582 ?end.}
  #Group directors
  SERVICE wikibase:label { 
    bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". 
    ?director rdfs:label ?directorLabel .
    ?item rdfs:label ?itemLabel .
  }
 }
GROUP BY ?item ?itemLabel
ORDER BY DESC(?rev) 
LIMIT 10

This query is a bad aggregate, if I add more variables to the GROUP BY clause it times out. Ultimately I would like to aggregate the wdt ids for all the directors too.

Korimako
  • 359
  • 3
  • 13
  • either you have to use the variables in aggregate functions or you have to add them to the `group by` part - there is no other way – UninformedUser Aug 09 '21 at 15:48
  • works for me: `SELECT DISTINCT ?item ?itemLabel ?rev ?date (group_concat(distinct ?directorLabel ; separator = ", ") as ?directors) WHERE { ?item wdt:P31/wdt:P279* wd:Q4830453 ; wdt:P17 wd:Q30 . ?item p:P2139 ?revSt . ?revSt pq:P585 ?date. hint:Prior hint:rangeSafe "true" .` – UninformedUser Aug 09 '21 at 15:53
  • `FILTER ( YEAR(?date) = 2020 ). ?revSt ps:P2139 ?rev . ?item p:P3320 ?relationship. ?relationship ps:P3320 ?director. FILTER NOT EXISTS {?relationship pq:P582 ?end.} SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". ?director rdfs:label ?directorLabel . ?item rdfs:label ?itemLabel . } } GROUP BY ?item ?itemLabel ?rev ?date ORDER BY DESC(?rev) LIMIT 10` – UninformedUser Aug 09 '21 at 15:53
  • Thanks! Please add this as an answer, and I will set it as correct. – Korimako Aug 09 '21 at 15:56

1 Answers1

1
SELECT DISTINCT 
?item ?itemLabel ?rev ?date 
(group_concat(distinct ?directorLabel ; separator = ", ") as ?directors) 
WHERE {    
  ?item wdt:P31/wdt:P279* wd:Q4830453 ;
        wdt:P17 wd:Q30 .
  ?item p:P2139 ?revSt .   
  ?revSt pq:P585 ?date. 
  hint:Prior hint:rangeSafe "true" .
  FILTER (   YEAR(?date) = 2020 ).   
  ?revSt ps:P2139 ?rev .  
  ?item p:P3320 ?relationship.   
  ?relationship ps:P3320 ?director.   
  FILTER NOT EXISTS {?relationship pq:P582 ?end.}  
  SERVICE wikibase:label { 
    bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en".   
    ?director rdfs:label ?directorLabel .    
    ?item rdfs:label ?itemLabel .  
   } 
 } 
GROUP BY ?item ?itemLabel ?rev ?date 
ORDER BY DESC(?rev)  
LIMIT 10
Matthias Winkelmann
  • 15,870
  • 7
  • 64
  • 76