這是一個很好的。這裏有一個近命中:
prefix wdt: <http://www.wikidata.org/prop/direct/>
prefix wd: <http://www.wikidata.org/entity/>
select ?p ?o (count(distinct ?chancellor) as ?cs) where {
?chancellor wdt:P39 wd:Q4970706.
?chancellor ?p ?o .
}
group by ?p ?o
order by desc(?cs)
Link to query
這需要所有的校長,以及它們的屬性和值。它計算每個prop/val的總理人數。
通過排序可以看到頂部最常見的prop/vals。
現在你想要的只是所有大臣的結果。我們可以得到校長的數量在一個查詢很輕鬆了,並堅持兩者結合起來:
prefix wdt: <http://www.wikidata.org/prop/direct/>
prefix wd: <http://www.wikidata.org/entity/>
select ?p ?o where {
{
# Find number of chancellors
select (count(?chancellor) as ?num_chancellors) where {
?chancellor wdt:P39 wd:Q4970706
}
}
{
# Find number of chancellors per predicate/value
select ?p ?o (count(distinct ?chancellor) as ?chancellor_count) where {
?chancellor wdt:P39 wd:Q4970706.
?chancellor ?p ?o .
}
group by ?p ?o
}
# Choose results all chancellors share
filter (?num_chancellors = ?chancellor_count)
}
Link to query。
我認爲這是做你想做的。我不是很漂亮,我承認。
很好的答案!方法#1也很有趣! #2正是我想要的。 – rinderwahn
查詢結果並不令人遺憾: - /通過使用group_concat而不是在第一個例子中計數,您可以看到哪些校友共享prop/vals,這是一個有用的變體。 – user205512