SPARQL选择计数器的最大值 [英] SPARQL selecting MAX value of a counter

查看:189
本文介绍了SPARQL选择计数器的最大值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是sparql的新手,他试图找出仅使用子查询而不选择新表来选择另一个查询的计数器最大值的最佳方法是什么.我正在处理一个相对较小的数据集,因此计算时间不是问题.

I'm new to sparql and trying to fegure out what is the best way to select the max value of a counter of another query without creating a new table, only using sub-queries. I'm working on a relatively small dataset so the computation time is not a problem.

SELECT ?p1 ?c1  (MAX(?cnt1) AS ?maxc)
WHERE{
{
SELECT ?p1 ?c1 (COUNT(?s1) AS ?cnt1)
WHERE {
    ?s1 ?p1 ?o1;
          a ?c1.
     }Group by ?p1 ?c1
#ORDER BY ?p1 DESC(?cnt1)
}

}GROUP BY ?p1

所以我期望每个?p1值都具有一行,最大?cnt1是合适的?c1

so I'm expecting to get a row for every value of ?p1 with the max ?cnt1 the suitable ?c1

我很确定这是这样做的方法,但是由于某种原因,这会导致我的端点崩溃.内部查询工作正常,并且同时按?p1和 c1只产生一行,最大值为空.

I'm pretty sure that is the way to do that but for some reason it causes my endpoint to crash. the inner query works fine and when grouping by both ?p1 and ?c1 it produces just one line and the max value is empty.

谢谢, 欧姆里

推荐答案

除非您同时按?p1和?c1进行分组,否则查询将崩溃. 分组时,所有出现在SELECT中的变量必须以太出现在GROUP或聚合函数中(MAX,COUNT等).

Your query will crash unless you are grouping by both ?p1 and ?c1. When grouping, all variables appearing in SELECT must ether appear in the GROUP or in an aggregation function (MAX, COUNT, etc.).

以下查询将为您提供计数器的最大值,但没有相应的?p1?c1.要拥有它们,您可能需要另一个包含FILTER的子查询...

The following query will give you the maximum value of your counter, but without the corresponding ?p1 ?c1. To have those, you will likely need another sub-query with a FILTER in it...

SELECT (MAX(?cnt1) AS ?maxc)
WHERE{
{
SELECT ?p1 ?c1 (COUNT(?s1) AS ?cnt1)
WHERE {
    ?s1 ?p1 ?o1;
          a ?c1.
     }Group by ?p1 ?c1
}
}

这篇关于SPARQL选择计数器的最大值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆