14

在 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)

但是这个查询不起作用。

4

3 回答 3

8

您可以GROUP BY通过在它们之间用空格列出多个变量(而不是列):

GROUP BY ?a ?b ?c
于 2013-01-23T14:19:21.500 回答
6

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)
于 2013-01-23T15:08:18.697 回答
-5

你有没有尝试过类似的东西

SELECT ?a+b+?c, (MIN(?y) AS ?d) Where { .... } GROUP BY (?a+?b+?c)

这在 SQL Server 中工作得很好

于 2013-01-23T11:17:56.457 回答