SPARQL - 你如何使用count? [英] SPARQL - How do you use count?

查看:1157
本文介绍了SPARQL - 你如何使用count?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个查询

  SELECT?s WHERE {?a< http://xmlns.com/foaf/ 0.1 / topic_interest> ?s} 

返回

  aaa 
aaa
aaa
bbb
bbb
ccc

但是,我想显示为

  aaa | 3 
bbb | 2
ccc | 1

我使用dotnetrdf。这是我试过的

  SELECT(COUNT(*)AS?s)WHERE {?a< http:// xmlns .com / foaf / 0.1 / topic_interest> ?s} 

这只是给我的行数是3080。 >

您能告诉我如何使它正确吗?



感谢



这是因为COUNT(*)只是对每个组的结果行计数。如果没有GROUP BY子句你的查询然后有一个隐含的所有结果组,因此你只是得到行数。



如果你添加一个GROUP BY到你的查询,如下面的例子,你应该获得所需的结果:

  SELECT(COUNT(*)AS?count)
WHERE
{
?a< http://xmlns.com/foaf/0.1/topic_interest> ?s}
} GROUP BY?s


I have this query

SELECT ?s WHERE {?a <http://xmlns.com/foaf/0.1/topic_interest> ?s}

which returns

aaa
aaa
aaa
bbb
bbb
ccc

However, I want to display it as

aaa | 3
bbb | 2
ccc | 1

I am using dotnetrdf. This is what i tried

SELECT (COUNT(*) AS ?s) WHERE {?a <http://xmlns.com/foaf/0.1/topic_interest> ?s}

and this just gives me the number of rows there are which is 3080.

Can you tell me how to make it right?

Thanks

解决方案

This is because COUNT(*) simply counts result rows for each group

If there is no GROUP BY clause in your query then there is one implicit group of all results hence you just get the number of rows.

If you add a GROUP BY to your query like the following example you should get the result you want:

SELECT (COUNT(*) AS ?count)
WHERE
{
  ?a <http://xmlns.com/foaf/0.1/topic_interest> ?s}
} GROUP BY ?s

这篇关于SPARQL - 你如何使用count?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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