count - SPARQL 中计数列的总和
问题描述
嗨,我是 SPARQL 的新手,需要帮助。我编写了一个查询,其中 GROUP_CONCAT 我的图像,然后我对我的图像字段进行了计数,结果如下所示
我现在想要的是 imageCount 字段的总和,如下图所示。在这个例子中,总数为 6
SELECT ?id
(GROUP_CONCAT(?images; separator=";") as ?images)
(count( ?images) as ?imageCount )
{
GRAPH <virtual://sample> {
....
....
}
GROUP BY ?id
LIMIT 10
对此有任何帮助!谢谢
解决方案
@fasalshah 评论的长度有限,因此发布相关数据作为答案
是的,使用以下示例数据:
insert data {
<id:1> <id:image> "aq.png" ; <id:select> 1 .
<id:2> <id:image> "a.png", "ab.png" ; <id:select> 1 .
<id:3> <id:image> "qw.png" ; <id:select> 1 .
<id:4> <id:image> "d1.png", "d2.png" ; <id:select> 1 .
<id:5> <id:image> "x.png", "y.png" ; <id:select> 2 .
}
和以下查询:
select ?key (group_concat(?image;separator=";") as ?list) (count(*) as ?count) where {
?id <id:image> ?image .
?id <id:select> 1 .
{
} union {
bind("this row accumulates everything" as ?totals)
}
bind (coalesce(?totals, ?id) as ?key)
} group by ?key
推荐阅读
- nestjs - 如何在 Nestjs 中的 typeorm 中正确配置 ormconfig.json 文件上的实体?
- python - 如何使我的列表理解(及其调用的函数)异步运行?
- java - 是否可以使用 Android / Flutter 关闭手机的所有振动?
- paraview - STL 表面上的点云,按元素集成
- regex - Apache Pig 中的正则表达式提取所需数据
- python - spacy 和 train 数据中的 Cased VS uncased BERT 模型
- file - Serilog 未写入从控制台 CORE 3 应用程序中的 appsettings.json 加载的配置的文件
- java - LeetCode 上的 Stock Span 问题是否有更好的解决方案?
- node.js - 使用 Lambda 自动化 NodeJS 应用程序(创建 json 文件)
- flutter - 最佳实践:在 GCF 内调用 Firebase 或在 GCF 之后再调用 Firebase