Sparql: how to GROUP BY More Than One Column

馋奶兔 提交于 2019-12-10 12:32:54

问题


In SPARQL, we can group the rows by a column through the gollowing syntax:

GROUP BY ?colName

Can we group by more than 1 columns eg:

GROUP BY (?colName1 + ?colName2 + ?colName3) 

Suppose a query like:

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

But this query does not work.


回答1:


You can GROUP BY multiple variables (not columns) by listing them with a space in between:

GROUP BY ?a ?b ?c



回答2:


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)



回答3:


Have you tried something like

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

This works in SQL Server just fine



来源:https://stackoverflow.com/questions/14477587/sparql-how-to-group-by-more-than-one-column

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!