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

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

问题描述

我有这个查询

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.这是我试过的

I am using dotnetrdf. This is what i tried

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

这只是给了我 3080 的行数.

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

你能告诉我怎么做吗?

谢谢

推荐答案

这是因为 COUNT(*) 只是对每组的结果行进行计数

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

如果您的查询中没有 GROUP BY 子句,则所有结果都是一个隐式组,因此您只会获得行数.

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.

如果像以下示例那样向查询添加 GROUP BY,您应该会得到想要的结果:

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 - 你如何使用计数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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