在 SPARQL 中,我们可以通过 gollowing 语法按列对行进行分组:
GROUP BY ?colName
我们可以按超过 1 列分组,例如:
GROUP BY (?colName1 + ?colName2 + ?colName3)
假设查询如下:
Select ?a ?b ?c (MIN(?y) AS ?d)
Where {
....
}
GROUP BY (?a + ?b + ?c)
但是这个查询不起作用。
您可以GROUP BY
通过在它们之间用空格列出多个变量(而不是列):
GROUP BY ?a ?b ?c
In addition to Ben Companjen's answer of
GROUP BY ?a ?b ?c
you need to fix the SELECT line as you can't pass out the indeterminate non-group keys without explicitly saying so e.g.
SELECT (sample(?a) as ?A) (sample(?b) as ?B) (sample(?c) as ?C) (min(?y) as ?d)
你有没有尝试过类似的东西
SELECT ?a+b+?c, (MIN(?y) AS ?d) Where { .... } GROUP BY (?a+?b+?c)
这在 SQL Server 中工作得很好