投影中的变量"x"在GROUP BY中不存在 [英] variable 'x' in projection not present in GROUP BY

查看:129
本文介绍了投影中的变量"x"在GROUP BY中不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想算一下市政当局以及括号内的数字.但是,我也想获取另一个变量,但是当我将其添加到SELECT时,我得到了:

I want to count municipalities and what I have in parentheses work. However, I want to get another variable too, but when I am adding it to SELECT, I am getting:

org.openrdf.query.MalformedQueryException:投影中的变量'region_name'在GROUP BY中不存在.

org.openrdf.query.MalformedQueryException: variable 'region_name' in projection not present in GROUP BY.

在我的查询中,我有:

"SELECT ?region_name (COUNT(?municipality) AS ?count) " +

我想念什么?

请注意,我在项目的任何地方都没有类似GROUP的东西,我认为这是在芝麻内部发生的.

Notice that I do not have anything like GROUP anywhere in my project, I think it is happening internally of Sesame.

我刚刚看到,如果删除(COUNT ...),我将得到预期的名字.

I just saw that if I remove (COUNT...), I am getting the names as expected.

推荐答案

在SPARQL中,每个查询使用聚合函数(例如COUNTSUMSAMPLE等) .)总是使用分组.即使您没有在查询中明确指定GROUP BY子句,它也会使用默认分组"(即所有解决方案所属的单个组).

In SPARQL, every query that uses an aggregate function (such as COUNT, SUM, SAMPLE, etc.) always uses a grouping. Even if you do not explicitly specify a GROUP BY clause in your query, it uses the 'default grouping' (that is, a single group to which all solutions belong).

在使用聚合的SPARQL查询中,除非未将未聚合的变量(例如?region_name)明确添加到分组中,否则可能不会在SELECT子句中进行投影.

In a SPARQL query which uses aggregates, non-aggregated variables (such as ?region_name) may not be projected in the SELECT clause, unless they are explicitly added to the grouping.

解决方法是在查询中添加明确的GROUP BY:

The fix is to add an explicit GROUP BY to your query:

SELECT ?region_name (COUNT(?municipality) AS ?count)
WHERE {
  ... 
}
GROUP BY ?region_name 

这篇关于投影中的变量"x"在GROUP BY中不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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