如何进行SPARQL查询以查找属性的最高值? [英] How do I make a SPARQL query to find the highest value for a property?
本文介绍了如何进行SPARQL查询以查找属性的最高值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有一个像age这样的谓词,其中所有的年龄三元组的值都是整数文字。什么SPARQL查询将返回数据中具有最高年龄的主题?
Lets say I have a predicate like 'age' where the values of all age triples are integer literals. What SPARQL query would return the subject with the highest age in the data?
推荐答案
您只需要执行 order by desc
使用年龄谓语,然后 limit
才能获得第一个。
You just need to do order by desc
with the age predicate and then limit
to just get the first one.
PREFIX ns: <http://namespace.org/ontology/>
SELECT ?s ?age
WHERE { ?s ns:age ?age }
ORDER BY DESC(?age) LIMIT 1
请参阅SPARQL中的 order by
的语义此处
See the semantics of order by
in SPARQL here
下一个版本的SPARQL 1.1在某些系统中支持你可以使用函数聚合和do ..
With the next version of SPARQL , 1.1, that is already supported in some systems you can use function aggregates and do ..
SELECT max(?age) as ?maxage
WHERE { ?s ns:age ?age }
目前不支持所有三联店。
This is not supported in all triple stores currently.
这篇关于如何进行SPARQL查询以查找属性的最高值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文