SPARQL:我有单个对象 属性 具有多个值的个体。如何转换为一条记录?

SPARQL : I have individual with multiple values for single object property. How to convert to one record?

当我查询时,它显示同一个人的三个记录,同一对象的三个不同值 属性。那么如何转换为单个记录呢? screenshot of query and result screenshot of query and result

的确GROUP_CONCAT是你的朋友。请在下面找到一个示例。

美国总统的昵称

查询

SELECT ?item ?itemLabel (GROUP_CONCAT(DISTINCT ?nickName; SEPARATOR=",") as ?nickNames)
WHERE 
{
  # president
  ?item wdt:P39 wd:Q11696.
  ?item wdt:P1449 ?nickName
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
} GROUP BY ?item ?itemLabel

try it!

结果

item itemLabel nickNames
http://www.wikidata.org/entity/Q23 George Washington American Fabius
http://www.wikidata.org/entity/Q76 Barack Obama Barry
http://www.wikidata.org/entity/Q1124 Bill Clinton The Comeback Kid,Slick Willie
http://www.wikidata.org/entity/Q6279 Joe Biden Joe
http://www.wikidata.org/entity/Q9588 Richard Nixon Dick,Dick Nixon
http://www.wikidata.org/entity/Q9696 John F. Kennedy Jack
http://www.wikidata.org/entity/Q9916 Dwight D. Eisenhower Ike
http://www.wikidata.org/entity/Q11817 Andrew Jackson Old Hickory
http://www.wikidata.org/entity/Q11820 Martin Van Buren Old Kinderhook
http://www.wikidata.org/entity/Q11869 William Henry Harrison Old Tippecanoe
http://www.wikidata.org/entity/Q11896 Zachary Taylor Old Rough and Ready
http://www.wikidata.org/entity/Q22686 Donald Trump The Donald
http://www.wikidata.org/entity/Q34836 Ulysses S Grant “Unconditional Surrender” Grant