维基数据:SPARQL,足球运动员的游戏数量

时间:2017-08-24 17:57:31

标签: sparql wikidata

我在https://query.wikidata.org/ -

使用了此查询
SELECT ?p ?pLabel (?oc as ?OC) (?sp as ?SP) WHERE {

?p wdt:P106/wdt:P279* wd:Q937857. # Soccer player

SERVICE wikibase:label {bd:serviceParam wikibase:language "en" . }

{ SELECT ?p (count(?oc) AS ?oc) WHERE { ?p wdt:P106 wd:Q937857; p:P106 ?oc. }  GROUP BY ?p HAVING(?oc<3)} # Occupation

{ SELECT ?p (count(?sp) AS ?sp) WHERE { ?p wdt:P106 wd:Q937857; p:P54 ?sp. } GROUP BY ?p HAVING(?sp>5)} # Sport Teams                                                                                                   
}

LIMIT 10

Query link

用Google搜索了几个小时后,找到了一种方法来计算所有球队(P1350)中每位球员的比赛次数(P54),我决定寻求帮助。

1 个答案:

答案 0 :(得分:3)

SELECT ?player ?playerLabel ?totalMatchesPlayed {

SERVICE wikibase:label {bd:serviceParam wikibase:language "en" . }

{
  SELECT ?player (sum(?matchesPlayed) as ?totalMatchesPlayed) WHERE {
    ?player wdt:P106/wdt:P279* wd:Q937857 . 
    ?player   p:P54/pq:P1350 ?matchesPlayed.
  }
  GROUP BY ?player
  LIMIT 100
}

}